-
-
Notifications
You must be signed in to change notification settings - Fork 12k
Open
Labels
Description
See below
>>> m = np.ma.array([None], mask=[False])
>>> m[0] = np.ma.masked; m[0]
masked
>>> m[0] = np.eye(3); m[0]
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
>>> m[0] = np.ma.masked; m[0]
masked_array(data =
[[-- -- --]
[-- -- --]
[-- -- --]],
mask =
[[ True True True]
[ True True True]
[ True True True]],
fill_value = 1e+20) # but that was the same line that we ran above!The culprit is the # Did we extract a single item? check in numpy/ma/core.py:3192.
I just don't think we have the information needed to actually know whether we got a single item from self.data, which could be of any subclass (?).
Maybe the code should become something like:
# Normalize the index. This is wrong, but being right is really hard (#8276)
if not isinstance(idx, tuple):
idx = (idx,)
# append an ellipsis if there was not already one, and remember whether we did
could_be_scalar = Ellipsis not in idx
if could_be_scalar:
idx = idx + (Ellipsis,)
# guaranteed to be a (possibly 0d) array and not a scalar element
dout = data[idx]
# flatten 0d arrays that were not requested
if could_be_scalar and dout.ndim == 0:
result = result[()]
return result#8276 (comment) for the lazy