-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
BUG: np.sum with keepdims=True
fails on masked_array
#7312
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
Conversation
This can be triggered even without the user passing
|
I'm working on a fix |
I've attached a fix! |
keepdims=True
fails on masked_arraykeepdims=True
fails on masked_array
# not supporting the keepdims option. | ||
|
||
# First make sure keepdims works when called explicitly | ||
result = np.sum(np.ma.masked_array([1,2,3],mask=[0,0,1]), keepdims=True) |
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.
Lots of PEP8 violations in this function (spaces after commas) -- could you fix that? Otherwise LGTM
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.
Oops, thanks for pointing that out - should be fixed now
…eepdims= keyword argument, and include regression test
8fbf36e
to
644865f
Compare
Before you work too hard on this, may I suggest looking at my PR #5706, which adds keepdims, and is finished but just waiting for a review. After a huge discussion, we concluded you can't directly add a |
@ahaldane: oh good point |
Just to clarify, this is causing test failures in Astropy, so it would be good to have this fix included in 1.11.0 final - thanks! |
@astrofrog: wait, this is a regression? Can you give an example of code that used to work but now doesn't, and which version it worked in? |
@njsmith - it is a regression but actually after double checking I think it doesn't affect 1.11.0 pre-releases. This works in Numpy 1.9, 1.10, and 1.11.0rc1 (using the git tag):
but fails in master:
So maybe we are ok for the 1.11.0 release |
We recently put in a PR fixing keepdims propagation to subclasses for things like sum. That probably is the reason. Which means that |
Ohh, yes, I never looked at this a lot. The issue here is not so much the lack of keepdims in MA as much as the use of keepdims in nanvar, etc. |
Tagging with 1.12 milestone, just so we revisit it before a release. |
☔ The latest upstream changes (presumably #5706) made this pull request unmergeable. Please resolve the merge conflicts. |
@ahaldane was this fixed? |
Yeah this is fixed. Closing. |
When calling
np.sum
on a masked array, and using thekeepdims
option, an error is raised: