-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
293ea24
ae8cd54
565fc75
8309d16
04d05f6
c76b5ad
bfcec09
f06a1f8
1303b3c
ad95df2
dc14e6b
8eeed6a
4fe3444
ba2c398
2e8e2ea
3a20796
40075b3
a83887b
3d1c7b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4537,7 +4537,7 @@ def quantile(a, | |
weights = _weights_are_valid(weights=weights, a=a, axis=axis) | ||
if weights.dtype != object: | ||
if np.any(np.isinf(weights)): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another general comment: as written, the common case has to go through a lot of checks. I think it would be better to optimize for the common case, and not worry too much about distinguishing failure cases. E.g., you can do just one evaluation with:
|
||
raise ValueError("Weights must be non-infinite.") | ||
raise ValueError("Weights must be finite.") | ||
elif np.any(np.isnan(weights)): | ||
raise ValueError("At least one weight is nan.") | ||
# Since np.isinf and np.isnan do not work in dtype object arrays | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4144,11 +4144,11 @@ def test_closest_observation(self): | |
|
||
|
||
@pytest.mark.parametrize(["err_msg", "weight"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd parametrize over There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
[("Weights must be non-infinite.", np.array([1,np.inf, 1, 1])), | ||
("Weights must be non-infinite.", np.array([1,np.inf, 1, 1], dtype=object)), | ||
("Weights must be non-infinite.", np.array([1,-np.inf, 1, 1])), | ||
("Weights must be non-infinite.", np.array([1,-np.inf, 1, 1], dtype=object)), | ||
("Weights must be non-infinite.", np.array([1,np.inf, 1, np.inf])), | ||
[("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])), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general comment: I think these checks should happen inside
_weights_ar_valid
- this will ensure they are used forpercentile
as well.