Do not warn when invalid values are masked in a MaskedArray
See original GitHub issueWhen doing a mathematical operation on a masked array, and some elements are invalid for the particular mathematical operation, numpy should not issue a warning if all invalid elements are masked.
This cannot be handled by numpy.seterr
: I want numpy to warn or raise when performing an invalid operation on any non-masked value, but to be silent when performing an invalid operation on a masked value.
In [1]: A = arange(-2, 5)/2
In [2]: Am = numpy.ma.masked_less_equal(A, 0)
In [3]: numpy.log10(Am)
/export/data/home/gholl/venv/gerrit/bin/ipython3:1: RuntimeWarning: divide by zero encountered in log10
#!/export/data/home/gholl/venv/gerrit/bin/python3.4
/export/data/home/gholl/venv/gerrit/bin/ipython3:1: RuntimeWarning: invalid value encountered in log10
#!/export/data/home/gholl/venv/gerrit/bin/python3.4
Out[3]:
masked_array(data = [-- -- -- -0.3010299956639812 0.0 0.17609125905568124 0.3010299956639812],
mask = [ True True True False False False False],
fill_value = 1e+20)
Issue Analytics
- State:
- Created 9 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Calling function on valid values of masked arrays
The problem. Calling the function directly worked because, when you call div(x,y) , div 's arguments a and b become the MaskedArrays x...
Read more >Missing data: masked arrays
When a masked array is created with no masked values, it's mask attribute does not contain a full Boolean array; this is to...
Read more >The numpy.ma module — NumPy v1.9 Manual
A mask is either nomask, indicating that no value of the associated array is ... If x has no invalid entry or is...
Read more >The concept of Masks in Python 2021 - Towards Data Science
Caution: Now, when the mask=False or mask=0 , it literally means do not label this value as invalid. Simply put, include it during...
Read more >numpy.ma.core - Dask documentation
numpy.ma : a package to handle missing or invalid values. ... If `a` is not a masked array, the function returns silently, without...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The problem also appears in simple comparisons:
@greglucas that sounds great, a PR would be nice.
Yes, I agree with those comments.