You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Object-type masked array special-cases elements that are ndarray #18981
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:
importnumpyasnp>>>m=np.ma.array([None, [1, 2], np.array([1, 2])], dtype=object)
>>>mmasked_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_arraymasked_array(data=[--, --],
mask=[ True, True],
fill_value=999999,
dtype=int64)
>>>m.data[2] # The data element under the mask is still the original ndarrayarray([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 ]
I expect this needs a check for object dtype (maybe together with a check for ndim == 1. Although, IIRC that logic is definitely pretty holey... It was not a regression in 1.19.x, right?
It also looks like there could be a conflict with another issue from about 10 years ago.
# special case introduced in gh-5962elif (self.dtype.typeisnp.object_andisinstance(dout, np.ndarray) anddoutisnotmasked):
# If masked, turn into a MaskedArray, with everything masked.ifmout:
returnMaskedArray(dout, mask=True)
else:
returndout
If we want to fix both of it, we must change the basic structure of masked......
Activity
seberg commentedon May 12, 2021
I expect this needs a check for
objectdtype (maybe together with a check forndim == 1. Although, IIRC that logic is definitely pretty holey... It was not a regression in 1.19.x, right?fengluoqiuwu commentedon Oct 26, 2024
It also looks like there could be a conflict with another issue from about 10 years ago.
If we want to fix both of it, we must change the basic structure of masked......