Skip to content

RuntimeWarning: invalid value encountered in absolute  #394

Closed
@certik

Description

@certik

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.])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions