Skip to content

RuntimeWarning: invalid value encountered in absolute  #394

Closed

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

Activity

  1. certik commented on Nov 14, 2012

    @certik
    ContributorAuthor

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

  2. charris commented on Feb 15, 2014

    @charris
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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