Skip to content
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

Merged
merged 1 commit into from
Oct 21, 2015
Merged

Potential fix for #6462 #6527

merged 1 commit into from
Oct 21, 2015

Conversation

ethankruse
Copy link
Contributor

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.

@njsmith
Copy link
Member

njsmith commented Oct 19, 2015

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.

@ethankruse
Copy link
Contributor Author

@njsmith Added some tests, I think I did it right, and it's looks like they're working as expected.

@charris
Copy link
Member

charris commented Oct 21, 2015

@ethankruse Take a look at doc/source/dev/gitwash/development_workflow.rst for proper formatting of commit messages. It would be good to also squash the commit. You can edit the commit messages and do the squasing with git rebase -i HEAD^^.

@charris
Copy link
Member

charris commented Oct 21, 2015

The commit message should also be more descriptive, something along the lines

BUG: Make numpy median work correctly for empty arrays.

<example of regression>

@ethankruse
Copy link
Contributor Author

@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)
Copy link
Member

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?

Copy link
Contributor Author

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.
charris added a commit that referenced this pull request Oct 21, 2015
@charris charris merged commit bf28b44 into numpy:master Oct 21, 2015
@charris
Copy link
Member

charris commented Oct 21, 2015

OK, merged. Thanks @ethankruse .

@charris charris removed this from the 1.10.2 release milestone Oct 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants