Making the issue more simple, let's assume:
y = np.ma.array([np.nan, 0.0, 2.0], mask=[1, 0, 0])
m = (y > 1.0)
print(y, y.shape) ; print(y[m], y[m].shape, m.shape)
and the output is:
[-- 0.0 2.0] (3,)
[2.0] (1,) (3,)
with the RuntimeWarning: /.../anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:2: RuntimeWarning: invalid value encountered in greater
.
Changing:
...
m = (y != 2.0)
...
We get:
[-- 0.0 2.0] (3,)
[-- 0.0] (2,) (3,)
so we have a masked element and the result without any RuntimeWarning.
Changing now:
...
m = y.mask.copy() ; y[np.isnan(y)] = 9.0 ; y.mask = m ; m = (y > 1.0)
...
We get (without RuntimeWorning):
[-- 0.0 2.0] (3,)
[-- 2.0] (2,) (3,)
This work-around is however strange (by setting arbitrary value in the place of np.nan
and mask saving). Comparing something with masked
should be always masked
, shouldn't it?