question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not warn when invalid values are masked in a MaskedArray

See original GitHub issue

When 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:open
  • Created 9 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
efiringcommented, Jan 16, 2017

The problem also appears in simple comparisons:

In [2]: np.ma.masked_invalid([1.1, np.nan]) > 1
/Users/efiring/anaconda/envs/test/bin/ipython:1: RuntimeWarning: invalid value encountered in greater
  #!/Users/efiring/anaconda/envs/test/bin/python

masked_array(data = [True --],
             mask = [False  True],
       fill_value = True)
1reaction
rgommerscommented, Apr 18, 2020

@greglucas that sounds great, a PR would be nice.

This idea was brought up in #15200 suggesting this may be a good thing to do.

Yes, I agree with those comments.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found