Skip to content

Commit e550018

Browse files
eric-wiesercharris
authored andcommitted
BUG: Ensure mask is preserved on scalars
By promoting and demoting between scalars and arrays where appropriate See numpy#7585
1 parent d86a959 commit e550018

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎numpy/ma/core.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5628,9 +5628,10 @@ def take(self, indices, axis=None, out=None, mode='raise'):
56285628
maskindices = getattr(indices, '_mask', nomask)
56295629
if maskindices is not nomask:
56305630
indices = indices.filled(0)
5631-
# Get the data
5631+
# Get the data, promoting scalars to 0d arrays with [...] so that
5632+
# .view works correctly
56325633
if out is None:
5633-
out = _data.take(indices, axis=axis, mode=mode).view(cls)
5634+
out = _data.take(indices, axis=axis, mode=mode)[...].view(cls)
56345635
else:
56355636
np.take(_data, indices, axis=axis, mode=mode, out=out)
56365637
# Get the mask
@@ -5641,7 +5642,8 @@ def take(self, indices, axis=None, out=None, mode='raise'):
56415642
outmask = _mask.take(indices, axis=axis, mode=mode)
56425643
outmask |= maskindices
56435644
out.__setmask__(outmask)
5644-
return out
5645+
# demote 0d arrays back to scalars, for consistency with ndarray.take
5646+
return out[()]
56455647

56465648
# Array methods
56475649
copy = _arraymethod('copy')

0 commit comments

Comments
 (0)