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

Appearance settings

fix quantile all zeros error #28597

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
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix quantile all zeros error
  • Loading branch information
ido gal committed Mar 27, 2025
commit 1dbd18016ce355a1feef40a4335dd1284e6442b9
2 changes: 2 additions & 0 deletions 2 numpy/lib/_function_base_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4537,6 +4537,8 @@ def quantile(a,
weights = _weights_are_valid(weights=weights, a=a, axis=axis)
if np.any(weights < 0):
raise ValueError("Weights must be non-negative.")
if np.all(weights == 0):
raise ValueError("Weights must contain non-zero value.")

return _quantile_unchecked(
a, q, axis, out, overwrite_input, method, keepdims, weights)
Expand Down
7 changes: 7 additions & 0 deletions 7 numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4110,6 +4110,13 @@ def test_quantile_weights_raises_negative_weights(self):
with pytest.raises(ValueError, match="Weights must be non-negative"):
np.quantile(y, 0.5, weights=w, method="inverted_cdf")

def test_quantile_weights_raises_all_zeros_weights(self):
y = [1, 2]
w = [0, 0]
with pytest.raises(ValueError, match="Weights must contain non-zero value."):
np.quantile(y, 0.5, weights=w, 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.

Could someone please provide guidance on the reasons for these failures and suggest steps to address them?

You can reproduce the linter failure observed in CI locally by running spin lint on your branch. Purging the extra blank line it complains about will allow spin lint to pass locally and in CI. I checked the full test suite locally on this branch and it seems "ok."

The Qemu job failure in CI is clearly unrelated so don't worry about that.

For bug fixes, we usually prefix commits and titles of PRs with BUG:. You can find the list of prefixes in our docs.

Note for other NumPy devs--gh-28594 is very similar to this.

@pytest.mark.parametrize(
"method",
sorted(set(quantile_methods) - set(methods_supporting_weights)),
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.