Skip to content

BUG: quantile should error when weights are all zeros #28595

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 19 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improved testing
  • Loading branch information
Tontonio3 committed Apr 2, 2025
commit ad95df2177320899dbf867c1db788ca719686f07
19 changes: 9 additions & 10 deletions numpy/lib/tests/test_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4144,22 +4144,21 @@ def test_closest_observation(self):


@pytest.mark.parametrize(["err_msg", "weight"],
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd parametrize over np.quantile and np.percentile as well - they should have the same errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, if you pass in a list rather than an array, you could parametrize over dtype=float and dtype=object, to make this a little more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

[("Weights must be finite.", np.array([1, np.inf, 1, 1])),
("Weights must be finite.", np.array([1, np.inf, 1, 1], dtype=object)),
("Weights must be finite.", np.array([1, -np.inf, 1, 1])),
("Weights must be finite.", np.array([1, -np.inf, 1, 1], dtype=object)),
("Weights must be finite.", np.array([1, np.inf, 1, np.inf])),
("At least one weight is nan.", np.array([1, np.nan, 1, 1])),
("At least one weight is nan.", np.array([1, np.nan, 1, 1], dtype=object)),
("At least one weight is nan.", np.array([1, np.nan, np.nan, 1])),
[("Weights must be finite.", [1, np.inf, 1, 1]),
("Weights must be finite.", [1, -np.inf, 1, 1]),
("Weights must be finite.", [1, np.inf, 1, np.inf]),
("At least one weight is nan.", [1, np.nan, 1, 1]),
("At least one weight is nan.", [1, np.nan, np.nan, 1]),
("At least one weight must be non-zero.", np.zeros(4))])
def test_inf_nan_err(self, err_msg, weight):
@pytest.mark.parametrize("dty", ["f8", "O"])
def test_inf_nan_err(self, err_msg, weight, dty):

m = "inverted_cdf"
q = 0.5
arr = [1, 2, 3, 4]
wgts = np.array(weight, dtype=dty)
with pytest.raises(ValueError, match=err_msg):
a = np.quantile(arr, q, weights=weight, method=m)
a = np.quantile(arr, q, weights=wgts, method=m)

class TestLerp:
@hypothesis.given(t0=st.floats(allow_nan=False, allow_infinity=False,
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy