Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeWarning: invalid value encountered in absolute #394

Closed
certik opened this issue Aug 30, 2012 · 2 comments
Closed

RuntimeWarning: invalid value encountered in absolute #394

certik opened this issue Aug 30, 2012 · 2 comments

Comments

@certik
Copy link
Contributor

certik commented Aug 30, 2012

Sometimes I am getting these errors when running tests:

======================================================================
ERROR: test_numeric.TestIsclose.test_ip_isclose_allclose([1e-08, 1, 1000020.0000000099], [0, nan, 1000000.0])
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ondrej/repos/numpy/py27/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/ondrej/repos/numpy/py27/lib/python2.7/site-packages/numpy/core/tests/test_numeric.py", line 1245, in tst_isclose_allclose
    assert_array_equal(isclose(x, y).all(), allclose(x, y), msg % (x, y))
  File "/home/ondrej/repos/numpy/py27/lib/python2.7/site-packages/numpy/core/numeric.py", line 1986, in allclose
    return all(less_equal(abs(x-y), atol + rtol * abs(y)))
RuntimeWarning: invalid value encountered in absolute

======================================================================
ERROR: test_numeric.TestIsclose.test_ip_isclose_allclose(nan, [nan, nan, nan])
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ondrej/repos/numpy/py27/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/ondrej/repos/numpy/py27/lib/python2.7/site-packages/numpy/core/tests/test_numeric.py", line 1245, in tst_isclose_allclose
    assert_array_equal(isclose(x, y).all(), allclose(x, y), msg % (x, y))
  File "/home/ondrej/repos/numpy/py27/lib/python2.7/site-packages/numpy/core/numeric.py", line 1986, in allclose
    return all(less_equal(abs(x-y), atol + rtol * abs(y)))
RuntimeWarning: invalid value encountered in absolute

These are caused by calling allclose(x, y) with for example x = array([1, nan, 2]) (the array contains nan). Then inside allclose, one calls abs on the array of nans, which produces the warning. It can be reproduced by simply doing:

>>> from numpy import array, abs, nan
>>> a = array([1, nan, 3])
>>> a
array([  1.,  nan,   3.])
>>> abs(a)
__main__:1: RuntimeWarning: invalid value encountered in absolute
array([  1.,  nan,   3.])
@certik
Copy link
Contributor Author

certik commented Nov 14, 2012

This is not an issue for the 1.7.0 release due to the commit ea23de8.

@charris
Copy link
Member

charris commented Feb 15, 2014

I believe the relevant tests have been fixed by catching the warning.

@charris charris closed this as completed Feb 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants