-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Potential fix for #6462 #6527
Potential fix for #6462 #6527
Conversation
Can you add a test case to make sure it stays fixed? To figure out where, my usual strategy is to grep the other test files to find some existing tests for median. |
@njsmith Added some tests, I think I did it right, and it's looks like they're working as expected. |
@ethankruse Take a look at |
The commit message should also be more descriptive, something along the lines
|
@charris Thanks for the style guideline tip. Should be updated and just about ready to go now. |
with warnings.catch_warnings(record=True) as w: | ||
warnings.filterwarnings('always', '', RuntimeWarning) | ||
assert_equal(np.median(a, axis=0), b) | ||
assert_equal(np.median(a, axis=1), b) |
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.
Do you need to check w[0]
here?
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.
Ah, no, those actually don't produce the warnings, just empty arrays. I had put everything into the catch blocks by default, but for those I guess it's meaningless. I can drop it and recommit.
np.median([]) returns NaN. Fixes bug/regression that raised an IndexError. Added tests to ensure continued support of empty arrays.
OK, merged. Thanks @ethankruse . |
This fixes the IndexError when taking the median of an empty array in the new median implementation (#6462). Taking the median over an axis of size 0 now returns a NaN as it had in previous implementations instead of the IndexError.