Closed
Description
ma.masked_where
documentation says that:
copy : bool
If True (default) make a copy of `a` in the result. If False modify
`a` in place and return a view.
But it fails to modify the array's mask when the original mask is empty:
Reproducing code example:
>>> import numpy as np
>>> import numpy.ma as ma
>>> a = ma.array([1, 2, 3, 4])
>>> a
masked_array(data=[1, 2, 3, 4],
mask=False,
fill_value=999999)
>>> ma.masked_where(a==3, a, copy=False)
masked_array(data=[1, 2, --, 4],
mask=[False, False, True, False],
fill_value=999999)
>>> a
masked_array(data=[1, 2, 3, 4],
mask=False,
fill_value=999999)
It works properly when there are some masked elements in the array already:
>>> a = ma.array([1, 2, 3, 4], mask=[1, 0, 0, 0])
>>> a
masked_array(data=[--, 2, 3, 4],
mask=[ True, False, False, False],
fill_value=999999)
>>> ma.masked_where(a==3, a, copy=False)
masked_array(data=[--, 2, --, 4],
mask=[ True, False, True, False],
fill_value=999999)
>>> a
masked_array(data=[--, 2, --, 4],
mask=[ True, False, True, False],
fill_value=999999)
Error message:
None.
NumPy/Python version information:
1.20.2 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)]
numpy-1.20.2-cp38-cp38-win_amd64.whl