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 on csgraph.shortest_path when edge lengths are NaN #5144

Closed
michael-s-crouch opened this issue Aug 12, 2015 · 1 comment · Fixed by #11202
Closed

RuntimeWarning on csgraph.shortest_path when edge lengths are NaN #5144

michael-s-crouch opened this issue Aug 12, 2015 · 1 comment · Fixed by #11202
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse.csgraph
Milestone

Comments

@michael-s-crouch
Copy link

The documentation for scipy.sparse.csgraph says that NaN entries will be treated as non-edges, the same as 0 or inf. But when using csgraph.shortest_path on a graph where some paths are impossible because of NaN edges, irrelevant warning messages are printed. These warning messages don't happen in the other cases.

>>> import numpy
>>> import scipy.sparse.csgraph as csgraph
>>> print csgraph.shortest_path(numpy.array([[0,numpy.inf],[numpy.inf,0]]))
[[  0.  inf]
 [ inf   0.]]
>>> print csgraph.shortest_path(numpy.array([[0,0],[0,0]]))
[[  0.  inf]
 [ inf   0.]]
>>> print csgraph.shortest_path(numpy.array([[0, numpy.nan], [numpy.nan, 0]]))
/Users/creidieki/.virtualenvs/bugtest/lib/python2.7/site-packages/numpy/ma/core.py:2200: RuntimeWarning: invalid value encountered in less_equal
  condition = umath.less_equal(mabs(xnew - value), atol + rtol * mabs(value))
bug.py:4: RuntimeWarning: invalid value encountered in greater
  print csgraph.shortest_path(numpy.array([[0,numpy.nan],[numpy.nan,0]]))
bug.py:4: RuntimeWarning: invalid value encountered in less
  print csgraph.shortest_path(numpy.array([[0,numpy.nan],[numpy.nan,0]]))
[[  0.  inf]
 [ inf   0.]]

Using numpy v1.9.2, scipy v0.16.0, python 2.7.10 in a clean virtualenv on os x 10.10.4.

@rgommers rgommers added defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse.csgraph labels Oct 9, 2015
@rgommers
Copy link
Member

rgommers commented Oct 9, 2015

thanks @creidieki. Those warnings are harmless but very annoying. They should be easy to avoid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect A clear bug or issue that prevents SciPy from being installed or used as expected scipy.sparse.csgraph
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants