MA has several strategies to implementing methods.
1) evaluate the method on y.data
, and make a new ma
with y.mask
. It may suppress any runtime warnings.
2) evaluate the method on y.filled()
# with the default fill value
3) evaluate the method on y.filled(1)
# or some other innocuous value
4) evaluate the method on y.compressed()
5) evaluate the method on y.data[~y.mask]
multiplication, for example use filled(1)
, and addition uses filled(0)
.
It appears that the comparisons are done with 1).
I haven't studied the ma
code in detail, but I don't think it does 5).
If you are using ma
just to avoid the runtime warning, there are some alternatives.
there's a collection of np.nan...
functions that filter out nan
before calculating
there are ways of surpressing runtime warnings
ufuncs
have a where
parameter that can be used to skip some elements. Use it with an out
parameter to define the skipped ones.
===
Looking a np.ma.core.py
I see functions like ma.less
.
In [857]: y = np.ma.array([np.nan, 0.0, 2.0], mask=[1, 0, 0])
In [858]: y >1.0
/usr/local/bin/ipython3:1: RuntimeWarning: invalid value encountered in greater
#!/usr/bin/python3
Out[858]:
masked_array(data=[--, False, True],
mask=[ True, False, False],
fill_value=True)
In [859]: np.ma.greater(y,1.0)
Out[859]:
masked_array(data=[--, False, True],
mask=[ True, False, False],
fill_value=True)
Looking at the code, ma.less
and such are a MaskedBinaryOperation
class, and use 1) - evaluate on the data
with
np.seterr(divide='ignore', invalid='ignore')
The result mask is logical combination of the arguments' masks.
https://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html#operations-on-masked-arrays