Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions kll_sketch/kll_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ def add(self, x: float) -> None:
self._compress_until_ok()

def extend(self, xs: Iterable[float]) -> None:
buf = self._levels[0]
for x in xs:
xv = float(x)
if math.isnan(xv) or math.isinf(xv):
raise ValueError("values must be finite")
buf.append(xv)
# ``self._levels[0]`` can be replaced during compaction, so we must
# append directly to the current buffer each iteration instead of
# keeping a stale reference (which would silently drop values).
self._levels[0].append(xv)
self._n += 1
if self._capacity_exceeded():
self._compress_until_ok()
Expand Down
13 changes: 13 additions & 0 deletions kll_sketch/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Pytest configuration ensuring the package is importable during tests."""
from __future__ import annotations

import sys
from pathlib import Path

# When pytest collects tests inside the installed package directory, the
# repository root (which contains the ``kll_sketch`` package) might not be on
# ``sys.path``. Add it explicitly so ``from kll_sketch import KLL`` works even
# when the tests are executed without installing the project as a package.
ROOT = Path(__file__).resolve().parents[2]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))