Skip to content

Commit dbb31b5

Browse files
Merge pull request #1 from SaridakisStamatisChristos/codex/find-reason-for-test-failures
Fix extend compaction bug and ensure tests import package
2 parents 907ff0e + b889340 commit dbb31b5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

kll_sketch/kll_sketch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ def add(self, x: float) -> None:
7070
self._compress_until_ok()
7171

7272
def extend(self, xs: Iterable[float]) -> None:
73-
buf = self._levels[0]
7473
for x in xs:
7574
xv = float(x)
7675
if math.isnan(xv) or math.isinf(xv):
7776
raise ValueError("values must be finite")
78-
buf.append(xv)
77+
# ``self._levels[0]`` can be replaced during compaction, so we must
78+
# append directly to the current buffer each iteration instead of
79+
# keeping a stale reference (which would silently drop values).
80+
self._levels[0].append(xv)
7981
self._n += 1
8082
if self._capacity_exceeded():
8183
self._compress_until_ok()

kll_sketch/tests/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Pytest configuration ensuring the package is importable during tests."""
2+
from __future__ import annotations
3+
4+
import sys
5+
from pathlib import Path
6+
7+
# When pytest collects tests inside the installed package directory, the
8+
# repository root (which contains the ``kll_sketch`` package) might not be on
9+
# ``sys.path``. Add it explicitly so ``from kll_sketch import KLL`` works even
10+
# when the tests are executed without installing the project as a package.
11+
ROOT = Path(__file__).resolve().parents[2]
12+
if str(ROOT) not in sys.path:
13+
sys.path.insert(0, str(ROOT))

0 commit comments

Comments
 (0)