fix: keep selected locations when supplementing - #23
Open
ChrisW09 wants to merge 1 commit into
Open
Conversation
``_supplement`` merged the selector's locations with a full set of quantile
candidates and then truncated the union with ``sorted(...)[:target_count]``.
``quantile_knots`` already returns ``target_count`` entries, so the union
always overflowed by exactly ``len(existing)`` and the truncation reliably
discarded the largest values -- the data-driven locations the selector had
just found, whenever they sat above the median.
Keep every existing location and fill only the shortfall, down-sampling the
quantile candidates by even spacing so the additions stay spread across the
range rather than bunching at the low end.
existing : [-0.995, -0.026, 0.969]
before : [-0.995 -0.714 -0.429 -0.143 -0.026 0.143] 2 of 3 kept
after : [-0.995 -0.714 -0.143 -0.026 0.714 0.969] 3 of 3 kept
Closes #18
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ChrisW09
force-pushed
the
fix/supplement-keeps-selected-locations
branch
from
July 27, 2026 20:25
66817f8 to
25cf672
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18.
Problem
When a target-aware selector returns fewer locations than
min_count,_supplementtopsthe set up with quantile candidates:
quantile_knotsalready returnstarget_countentries, so the union always overflows byexactly
len(existing)— and truncating a sorted list always removes the largest values.The step meant to add to the selector's findings systematically deleted them instead,
whenever they sat above the median.
Fix
Keep every existing location; fill only the shortfall. The quantile candidates used as
filler are down-sampled with
select_knots(even spacing) rather than sliced, so theadditions stay spread across the range instead of bunching at the low end.
Result
Isolating the call, with three tree-selected locations and a target of 6:
End to end, a feature with few distinct values (so the tree places only three spaced splits
against a
min_countof 6) now retains all three:A correction to the issue
The second reproduction in #18's description did not actually reach
_supplement— Iinstrumented it and the method is never called for that input, so the bunching it showed has
a different cause. I have commented on the issue
with that correction and a repro that does exercise the path. The first reproduction in the
issue was accurate.
Tests
Four added to
tests/test_location_selectors.py:test_supplement_keeps_every_existing_location— the reported casetest_supplement_fills_only_the_shortfalltest_supplement_is_a_noop_when_already_fulltest_supplement_spreads_the_added_candidates— guards the low-end bias specificallyFull suite: 484 passed, 9 xfailed.
ruff checkclean on both changed files; pyrightunchanged at its pre-existing 71 errors.
🤖 Generated with Claude Code