-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Initializing a MaskedArray using mask=np.bool_(False) gives inconsistent mask result #13758
Comments
The cause is that a test is done for whether the input mask is
So, at least it is consistent that if you define But it might be good to document this... |
I don't think we can change the |
Thanks for the explanations! For me the root issue is really the |
Agreed that that was a design mistake. Since all tests that we have are of the form Anyway, for now definitely important to document it. |
The sliceable singleton seems like a pretty clever idea if you can make it work! |
Please consider also issue #7781. The fact that >>> import numpy as np
>>> a = np.ma.array(np.arange(10).reshape(2,-1))
>>> a
masked_array(
data=[[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9]],
mask=False,
fill_value=999999)
>>> a[0][0] = np.ma.masked # does not work because mask is False
>>> a
masked_array(
data=[[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9]],
mask=False,
fill_value=999999)
>>> a[-1,-1] = np.ma.masked # this obviously works
>>> a
masked_array(
data=[[0, 1, 2, 3, 4],
[5, 6, 7, 8, --]],
mask=[[False, False, False, False, False],
[False, False, False, False, True]],
fill_value=999999)
>>> a[0][0] = np.ma.masked # now mask is an array, so this works as expected
>>> a
masked_array(
data=[[--, 1, 2, 3, 4],
[5, 6, 7, 8, --]],
mask=[[ True, False, False, False, False],
[False, False, False, False, True]],
fill_value=999999) The fact that |
As #13980 seems stale, can I make my own PR? |
@panpiort8 - sure! |
This behavior was documented.
This idea is possibly still actionable. It does go well beyond the scope of of this issue though, and it's not clear if it's worth the effort. Removing |
The documentation part was the most important - the auto-conversion is a nice idea, but I think hard to get right and given that there are efforts to start afresh with MaskedArray, probably better to leave it to those. (Though it would probably be good to document how one actually wants a masked array to behave first....) [sorry for writing in the wrong place first!] |
Initializing a
MaskedArray
usingmask=np.bool_(False)
gives a different result thanmask=False
. Note thatnp.bool_(False)
is what one gets forMaskedArray([1, 2]).mask
.Reproducing code example:
Numpy/Python version information:
1.16.4 3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
The text was updated successfully, but these errors were encountered: