Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: bugfix for #28589 (quantile should error when weights are all zeros)#28594

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
rottenstea wants to merge1 commit intonumpy:main
base:main
Choose a base branch
Loading
fromrottenstea:quantile_error_fix

Conversation

rottenstea
Copy link

This commit addresses the following BUG: quantile should error when weights are all zeros#28589

Previously, np.quantile with all weights set to zero returned the first sample. This is fixed now via adding an explicit check that raises a ValueError when all weights are zero, preventing division by zero in the CDF.

  • Added the weight check in_quantile (line 4874 ff) to detect all-zero weights and raise an error.
  • Added a test intest_function_base.py to verify this behavior.
  • Added a second test to ensure existing quantile functionality remains unchanged.

This shouldclose#28589

…eights are all zerosnumpy#28589Previously, np.quantile with all weights set to zero returned the first sample. This is fixed now via adding an explicit check that raises aValueError when all weights are zero, preventing division by zero in the CDF.- Added the weight check in `_quantile` (line 4874 ff) to detect all-zero weights and raise an error.- Added a test in `test_function_base.py` to verify this behavior.- Added a second test to ensure existing quantile functionality remains unchanged.This shouldclosenumpy#28589
result = np.quantile(arr, quantile, weights=weights, method='inverted_cdf')
expected = 2.5

assert np.isclose(result, expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hopefully this part of the diff isn't really needed--presumably we have sufficient testing that if you broke the numerical behavior ofquantile an existing test would fail.

That said, this test actually does fail--maybe there is a problem with the test design?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As an aside,assert_allclose() is generally preferable in testing--it tends to give better feedback when something fails, etc.

weights = np.array([0, 0, 0, 0])

with pytest.raises(ValueError, match="All weights are zero, cannot compute quantile."):
np.quantile(arr, quantile, weights=weights, method='inverted_cdf')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Note for other NumPy devs--this/this PR is very similar togh-28597

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tylerjereddytylerjereddytylerjereddy left review comments

Assignees
No one assigned
Projects
Status: Pending authors' response
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

BUG:quantile should error whenweights are all zeros
2 participants
@rottenstea@tylerjereddy

[8]ページ先頭

©2009-2025 Movatter.jp