Open
Description
The MaskedArray
class has unexpected special-casing of ndarray
objects within an object array. I expect an object array to be a generic container of whatever is in each cell, and if that element is masked then accessing it should always return np.ma.masked
. Instead MaskedArray
appears to turn the ndarray
into a fully-masked MaskedArray
.
Reproducing code example:
import numpy as np
>>> m = np.ma.array([None, [1, 2], np.array([1, 2])], dtype=object)
>>> m
masked_array(data=[None, list([1, 2]), array([1, 2])],
mask=False,
fill_value='?',
dtype=object)
>>> m.mask = [True, True, True]
>>> m[0]
masked
>>> m[1]
masked
>>> m[2] # Accessing the ndarray has auto-magically converted it to masked_array
masked_array(data=[--, --],
mask=[ True, True],
fill_value=999999,
dtype=int64)
>>> m.data[2] # The data element under the mask is still the original ndarray
array([1, 2])
Expected:
>>> m[2]
masked
Error message:
N/A
NumPy/Python version information:
1.19.5 3.7.9 (default, Aug 31 2020, 07:22:35)
[Clang 10.0.0 ]