Skip zero-weight rows in MicroSeries.quantile - #287
Merged
Conversation
MaxGhenis
commented
Apr 17, 2026
MaxGhenis
left a comment
Collaborator
Author
There was a problem hiding this comment.
Self-review. Verified:
nonzero = sample_weight > 0filter applied before the CDF search; if no rows have positive weight, returnnp.nan(scalar q) or a NaN-filled Series (array q) — documented behaviour.- Fix addresses both the q=0 case and internal zero-weight plateaus because filtering happens before
argsort/cumsum. - Regression test covers q=0 with first-row zero weight, internal plateau (sweeping
np.linspace(0,1,21)to assert the zero-weight value never appears), and all-zero-weight → NaN. - Does not perturb the correct-weight path (all tests still pass).
- CI green Py 3.9-3.13.
Previously, when the first (or an internal) sorted element had weight 0, the inverse-CDF search still picked it. E.g. MicroSeries([10, 20, 30], weights=[0, 1, 1]).quantile(0) returned 10 instead of 20. The fix drops zero-weight rows before sorting and computing the CDF. An all-zero-weight series returns NaN (previously raised).
MaxGhenis
force-pushed
the
fix/quantile-zero-weight-first-row
branch
from
April 17, 2026 16:16
79013c9 to
71ce6e1
Compare
This was referenced Aug 31, 2026
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.
Summary
MicroSeries.quantilecould select a zero-weight element becausenp.searchsorted(cumsum_norm, 0, side='left')always returns 0, and the same class of bug fired at internal plateaus of zero weight. The fix drops zero-weight rows before sorting and computing the CDF; an all-zero-weight series returns NaN.Reproduction
Test plan
test_quantile_skips_zero_weight_rowscovers: