-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Masked array set slice fails with np.ma.masked on right side #8624
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
Labels
component: numpy.ma
masked arrays
Comments
Interestingly, this works as expected:
|
A related bug came up in #8510, which I'll repeat here since that wasn't the focus of that issue: >>> arr = np.ma.arange(5)
>>> arr[1:3] = [1, np.ma.masked]
ValueError: setting an array element with a sequence.
#expected result:
>>> arr
masked_array(data = [0 1 -- 3 4],
mask = [False False True False False],
fill_value = 999999) |
Your code fails in the same way as the above for me on both master and 1.11.1 |
This no longer reproduces and this problem is "fixed" >>> x = np.ma.MaskedArray([1,2,3])
>>> x[:2] = [100, np.ma.masked]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/numpy/ma/core.py", line 3323, in __setitem__
_data[indx] = dval
File "/usr/local/lib/python3.6/dist-packages/numpy/ma/core.py", line 4312, in __int__
raise MaskError('Cannot convert masked element to a Python int.')
numpy.ma.core.MaskError: Cannot convert masked element to a Python int. >>> x = np.ma.MaskedArray([1,2,3])
>>> x[:2] = np.ma.asarray([100, np.ma.masked], dtype=int)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/numpy/ma/core.py", line 7771, in asarray
subok=False, order=order)
File "/usr/local/lib/python3.6/dist-packages/numpy/ma/core.py", line 2788, in __new__
order=order, subok=True, ndmin=ndmin)
File "/usr/local/lib/python3.6/dist-packages/numpy/ma/core.py", line 4312, in __int__
raise MaskError('Cannot convert masked element to a Python int.')
numpy.ma.core.MaskError: Cannot convert masked element to a Python int. >>> arr = np.ma.arange(5)
>>> arr[1:3] = [1, np.ma.masked]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/numpy/ma/core.py", line 3323, in __setitem__
_data[indx] = dval
File "/usr/local/lib/python3.6/dist-packages/numpy/ma/core.py", line 4312, in __int__
raise MaskError('Cannot convert masked element to a Python int.')
numpy.ma.core.MaskError: Cannot convert masked element to a Python int. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following behavior is not what I would expect and seems like a bug:
One can correctly set a single item (e.g.
x[2] = np.ma.masked
) or set a slice to a scalar (x[:2] = np.ma.masked
).I'm using numpy 1.11.3.
The text was updated successfully, but these errors were encountered: