File tree Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Expand file tree Collapse file tree 3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change 1212 - uses : actions/setup-python@v5
1313 with :
1414 python-version : " 3.11"
15- - run : python -m pip install --upgrade pip pytest
16- - run : python -m pytest -q
15+ - name : Install dependencies
16+ run : |
17+ python -m pip install --upgrade pip
18+ python -m pip install -r kll_sketch/requirements-test.txt
19+ - name : Run tests with coverage
20+ run : python -m pytest --cov=kll_sketch --cov-report=term-missing --cov-report=xml kll_sketch/tests
1721 - name : Upload coverage reports to Codecov
1822 uses : codecov/codecov-action@v5
1923 with :
Original file line number Diff line number Diff line change 1212import struct
1313import random
1414import heapq
15- from bisect import bisect_left
15+ from bisect import bisect_left , bisect_right
1616from typing import Iterable , List , Tuple , Optional
1717
1818
@@ -205,6 +205,13 @@ def _capacity_exceeded(self) -> bool:
205205 return self ._total_items () > int (self ._k * self ._SOFT_CAP_FACTOR )
206206
207207 def _level_capacity (self , level : int ) -> int :
208+ # Preserve exactness while the total population fits inside ``k`` by
209+ # deferring compaction. This mirrors the streaming ingestion behaviour
210+ # where no compression is triggered before exceeding ``k`` items, which
211+ # keeps small merges numerically identical to simple extension.
212+ if self ._n <= self ._k :
213+ return self ._k
214+
208215 # Geometric schedule; sum over levels ≈ O(k)
209216 base = max (self ._LEVEL_BASE_MIN , self ._k // 8 )
210217 return base * (1 << max (0 , level ))
@@ -399,7 +406,7 @@ def _batched_quantiles(self, qs: List[float]) -> List[float]:
399406 search_lo = 0
400407 for idx , q in ordered :
401408 target = q * (self ._n - 1 )
402- pos = bisect_left (prefix , target - 1e-12 , lo = search_lo )
409+ pos = bisect_right (prefix , target , lo = search_lo )
403410 if pos >= len (vals ):
404411 pos = len (vals ) - 1
405412 out [idx ] = vals [pos ]
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ test = [
3333]
3434
3535[tool .pytest .ini_options ]
36- addopts = " --strict-config --strict-markers --cov=kll_sketch --cov-report=term-missing"
36+ addopts = " --strict-config --strict-markers --cov=kll_sketch --cov-report=term-missing --cov-report=xml "
3737testpaths = [" kll_sketch/tests" ]
3838filterwarnings = [
3939 " error" ,
You can’t perform that action at this time.
0 commit comments