Skip to content

weighted_percentile should error/warn when all sample weights 0 #31032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lucyleeow opened this issue Mar 20, 2025 · 1 comment
Open

weighted_percentile should error/warn when all sample weights 0 #31032

lucyleeow opened this issue Mar 20, 2025 · 1 comment
Labels

Comments

@lucyleeow
Copy link
Member

Describe the bug

Noticed while working on #29431

Steps/Code to Reproduce

See the following test:

def test_weighted_percentile_zero_weight():
y = np.empty(102, dtype=np.float64)
y.fill(1.0)
sw = np.ones(102, dtype=np.float64)
sw.fill(0.0)
value = _weighted_percentile(y, sw, 50)
assert approx(value) == 1.0

Expected Results

Error or warning should probably be given. You're effectively asking for a quantile of a empty array.

Actual Results

When all sample weights are 0, what happens is that percentile_in_sorted (as in the index of desired observation in array is the) is 101 (the last item). We should probably add a check and give a warning when sample_weights is all zero

cc @ogrisel @glemaitre

Versions

n/a
@adrinjalali
Copy link
Member

cc @antoinebaker too on this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants