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
If masked arrays are compared (through the >, >=, < and <= operators to constants, arrays or other masked arrays they access the masked out elements for comparison. In some extreme cases this fails, often causing a warning.
throws a warning __main__:1: RuntimeWarning: invalid value encountered in greater.
I think masked out elements should be set to False by default and not compared, so that operations such as:
d[d > 0] = 0
have the expected behavior. However that might cause issues in other cases such as:
np.all(d > 0)
This issue has been brought up before here: #4959, but the initial issue there seems more about using default functions such as np.log with masked array insted of the np.ma relative.
Even adding a fill_value seems not to fix this. At least in that case I would assume that for elements that are masked out the comparison happens with respect to the fill value.
Thinking about this a bit more, I think comparison operators should all return masked boolean arrays. Masked out elements in any of the compared arrays should stay masked in the returned array, all elements unmasked in both arrays should be returned unmasked with the comparison operator evaluated. Furthermore, it should be possible to index arrays with masked arrays, where only unmasked elements are accessed (boolean indexing or integer indexing). The returned arrays, probably have to be masked again, with masked elements in the indexing matrix being masked. That would mean that also standard numpy.ndarray need to know how to be indexed through masked arrays.
This seems to be a major change, so I'm not sure if it is within the scope of numpa.ma, could be implemented in an external library as proposed in #16022.
Uh oh!
There was an error while loading. Please reload this page.
If masked arrays are compared (through the
>
,>=
,<
and<=
operators to constants, arrays or other masked arrays they access the masked out elements for comparison. In some extreme cases this fails, often causing a warning.Reproducing code example:
This example
fails with a
TypeError: '>' not supported between instances of 'NoneType' and 'int'
.This example
throws a warning
__main__:1: RuntimeWarning: invalid value encountered in greater
.I think masked out elements should be set to
False
by default and not compared, so that operations such as:have the expected behavior. However that might cause issues in other cases such as:
This issue has been brought up before here: #4959, but the initial issue there seems more about using default functions such as
np.log
with masked array insted of thenp.ma
relative.Even adding a
fill_value
seems not to fix this. At least in that case I would assume that for elements that are masked out the comparison happens with respect to the fill value.creates the same error as mentioned above.
Numpy/Python version information:
The text was updated successfully, but these errors were encountered: