-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
ENH: add ndenumerate specialization for masked arrays #20020
Conversation
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.
The .pyi
addition looks good to me.
As far as the general concept is concerned: I would like to see the opinion of someone more involved with masked arrays.
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.
One thing that is most definitely missing from this PR is a set of tests.
Three useful test cases would be masked arrays with all-False
, all-True
and mixed True
/False
masks.
Ah, I thought the basic example in the docstring could maybe be sufficient, but you're right: there is no reason not to have some real tests. I struggled to recognize a coding style in the existing tests and did my best to write something sensible. I have no idea why the CircleCI tests are failing. |
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.
RuntimeError: Missing
SVML
submodule! Rungit submodule update --init
to fix this.
The CircleCI error seems to be unrelated, though I'm wondering if it is a fluke or not.
In any case, I don't have any particularly strong feelings about masked arrays, but the new np.ma.ndenumerate
implementation looks solid enough.
Maybe a rebase/merge off main would fix it? |
That did the trick, thank you! |
I think we should put this in. If it exists on ndarray, it should exist on ma. |
From the mailing list discussion:
|
I added a commit on top of this MR with the additional kwarg. I hope this is in line with expectations. |
Was there consensus around the |
There was no consensus, just a request for the functionality. One of the key reasons to have the specialization is that with |
We discussed this briefly in the triage meeting, but did not want to decide on this. Maybe we should ping the mailing list once more on the exact addition (since it is new API). Not that I particularly expect a lot of input. In general, the PR seems pretty much ready, and we should just make a decision to merge or not soon, though. |
This sounds reasonable to me. @mattip Any reservations? |
Thanks for the change in the example. This looks good to me, I will leave it for a little while in case anyone else wants to take a look. |
Thanks @joukewitteveen |
Hi-five on merging your first pull request to NumPy, @joukewitteveen! We hope you stick around! Your choices aren’t limited to programming – you can review pull requests, help us stay on top of new and old issues, develop educational material, work on our website, add or improve graphic design, create marketing materials, translate website content, write grant proposals, and help with other fundraising initiatives. For more info, check out: https://numpy.org/contribute |
Using
ndenumerate
on a masked array does not yieldma.masked
for masked values, but rather the actual value of the underlying data array. This makes sense from a performance perspective, but is potentially undesirable. Rather than filling the masked array before usingndenumerate
and incurring a copy, we can use a simplendenumerate
wrapper specifically for masked arrays. This MR suggests such a specialization ofndenumerate
.An 'upcoming changes' message is still missing as this is this functionality is proposed without prior discussion and I want to know what people think first.
At least in 2011 I could find someone else wanting this functionality too: https://stackoverflow.com/questions/8620798/numpy-ndenumerate-for-masked-arrays/8621173.