8000 REV: Add MaskedArray creation from non nd-array back in by greglucas · Pull Request #20386 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

REV: Add MaskedArray creation from non nd-array back in #20386

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

Merged
merged 2 commits into from
Nov 16, 2021

Conversation

greglucas
Copy link
Contributor
@greglucas greglucas commented Nov 16, 2021

This code path was removed in beacb39. This adds back in the MaskedArray portion of that commit and also fixes the _shared_mask attribute of the new MaskedArray . A test with a Quantity-like (non inherited, but still acts like a MaskedArray) class for this case.

closes #20372

@github-actions github-actions bot added the 34 - Reversion Reversion of previous commit or merge label Nov 16, 2021
numpy/ma/core.py Outdated
# still has the _mask attribute like MaskedArrays
if hasattr(data, '_mask') and not isinstance(data, ndarray):
_data._mask = data._mask
_data._sharedmask = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that actually there before, I think this is a bug-fix probably? I feel there was some discussion about it being _sharedmask = True rather than _data._sharedmask = True?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the discussion thread: #19102 (comment)
with the previous code removed from that commit

            # FIXME: should we set `_data._sharedmask = True`? 
            # Previously this set `_sharedmask = True`, but
            # that didn't actually do anything as the variable was unused!

I think this makes sense from the standpoint of when we are putting the incoming data._mask onto the new object, we should inform the original object that it is now sharing its mask with something else. I agree that it is not a full reversion in that sense, but I wasn't sure whether to call this a fix or revert PR, since the revert part is probably more important to get across. Happy to remove this and go back to a pure revert, or I can also add this "fix" piece as a separate commit if that would be more clear too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am good with this (might rename the PR title, but that is all). I just wanted to make sure that you are certain that it is correct (if we could add a test for it that would be awesome).
Basically, I am not deep into masked arrays, so just probing to build my trust in the fix ;).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, good suggestion to dig into this a bit more @seberg :)
Adding _data.sharedmask = True would actually break the case where keep_mask=False and overrides the mask later, but doesn't update the _sharedmask attribute. I decided to leave this as purely a partial revert of that commit and added a new test for that case I found at the end here as well.

Another option is to fix this by adding in the _data._sharedmask = True here and forcing sharedmask = False in the if statement here:

if not keep_mask:
. But, I think that should be for a separate FIX PR if someone thinks it is necessary/desirable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But, I think that should be for a separate FIX PR if someone thinks it is necessary/desirable.

Sounds good. There are not many actively invested in masked arrays. So if you think it is desirable than that is definitely "someone" :).

@charris charris added this to the 1.22.0 release milestone Nov 16, 2021
This code path was removed in beacb39. This adds back in the
MaskedArray portion of that commit. A test with a Quantity-like
(non inherited, but still acts like a MaskedArray) class for
this case.
@greglucas greglucas force-pushed the rev-masked-array-no-inheritance branch from 9d96222 to 90ca9be Compare November 16, 2021 17:01
@seberg
Copy link
Member
seberg commented Nov 16, 2021

Thanks for the quick fix @greglucas! If you feel like following up, please do. We would only put that in after branching 1.22.x anyway, so it would sit on the development/main branch for a while.

let me know if you want me to squash the commit out for cleanliness.

Just going to squash-merge, no need.

@seberg seberg merged commit b31a3a3 into numpy:main Nov 16, 2021
@greglucas greglucas deleted the rev-masked-array-no-inheritance branch November 16, 2021 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
34 - Reversion Reversion of previous commit or merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: removal of mask copy code may have broken matplotlib test
3 participants
0