-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG Ensure masked object arrays can always return single items. #5962
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
p.s. Bug found by testing astropy -- see astropy/astropy#3848. It seems our test suite checks even the dark corners of numpy! |
Would not be the first time we've tested out dark corners of Numpy :) |
Probably a case where a little light pollution would be a good thing ;) |
Just face it, you guys are basically the MA maintainers now ;) |
Thanks but no thanks ;-) It does look like travis passes; I think this is fine, but is there anyone else that should have a look? |
# A record ................ | ||
if isinstance(dout, np.void): | ||
mask = _mask[indx] | ||
mask = nomask if _mask is nomask else _mask[indx] |
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.
This line is a second bugfix, unrelated to object arrays, right?
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.
That's right -- did that in the process and forgot about it...
I'll add a test...
(BTW, shall I volunteer you for maintainer........)
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.
Actually, it seems one cannot initialise a MaskedArray
with record type and nomask
, so I'll just get rid of that change.
6bd731b
to
c4c2eee
Compare
@ahaldane - thanks for checking! The extraneous change is now removed. |
I'm going to have to pass on the maintainership :) The PR looks good now. |
c4c2eee
to
84fa8d9
Compare
@ahaldane - it turns out the fix I had was not enough: at least in astropy there are tests that rely on the previous buggy behaviour where the array held in the masked object array was returned as a At least all the tests in astropy now pass that previously failed because of my PR (but it seems some recent change in |
c1cfd7e
to
6049392
Compare
That's worrying.. which tests? I just tried building+testing astropy with this PR, and I don't see anything (8753 passed, 199 skipped, 43 xfailed, 2 xpassed ) |
@ahaldane - there definitely failures in None of these errors are related to the ones solved by this PR, though. EDIT: sadly, #5943 does not resolve the |
@mhvk Fixing the |
@mhvk I'm happy to help debug this, if you know which tests fail.
|
hmm, so a python3 issue for |
6049392
to
0db6200
Compare
@mhvk I agree that this is a bug fix |
For a masked array holding objects that themselves are arrays, when selecting a single item, it is treated as if it were a slice of the array and an attempt is made to set its mask. This was always a bug, but it become visible with a recent change to `MaskedArray.__getitem__` (numpygh-4586) where it is attempted to change the shape of the mask. With this PR, this case gets special treatment in that the object is made into a Masked Array with a full set mask. (A previous attempt to do the perhaps more logical think and just return `masked` caused quite a few errors in astropy.io.votable; it seemed it was not worth breaking backwards compatibility that much). Test case that now works but used to fail: ``` mx1 = MaskedArray([1.], mask=[True]) mx2 = MaskedArray([1., 2.]) mx = MaskedArray([mx1, mx2], mask=[False, True]) mx[0] ```
0db6200
to
1a4d943
Compare
OK, I added a brief item to the release notes, and corrected my commit message. Let me know if this makes sense. |
BUG Ensure masked object arrays can always return single items.
Thanks @mhvk. |
This PR introduced a different bug - #8906. Do we need to keep this behaviour of not just returning |
For a masked array holding objects that themselves are arrays, when selecting a single item, it is treated as if it were a slice of the array and an attempt is made to set its mask. This was always a bug, but it become visible with a recent change to
MaskedArray.__getitem__
(#4586) where it is attempted to change the shape of the mask (to help matrices, sigh, was not even part of PR initially!). With this PR, the treatment is the same as for other single items: one either gets the array stored in the object, or masked.Test case that now works but used to fail: