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
{{ message }}
Repository navigation
RuntimeWarning: invalid value encountered in absolute #394
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.])
Activity
certik commentedon Nov 14, 2012
This is not an issue for the 1.7.0 release due to the commit ea23de8.
charris commentedon Feb 15, 2014
I believe the relevant tests have been fixed by catching the warning.