I meet FloatingPointError: invalid value encountered in subtract in a piece of test code. The exception was thrown without any changes to the code itself, so I had trouble understanding it.
My question is: what causes the invalid value encountered in subtract exception? Why should this behave differently on different python + numpy installations?
DETAILS:
This MWE does not raise a FloatingPointError :
>>> import numpy as np >>> np.__version__ '1.6.1' >>> x = np.arange(5,dtype='float64') >>> y = np.ones(5,dtype='float64') >>> x[2]=np.nan >>> xy
However, deep inside the piece of code, I subtract two np.float64 ndarray and get a floating point exception. The arrays that throw the exception contain some pretty huge and tiny numbers (like 1e307 and 1e-307) and some nan s, but I didn't make any combinations of these numbers as a result of testing the exceptions myself.
Much more disturbing, I have a large grid of Jenkins tests that work with the same code with many versions of numpy, matplotlib, python, and scipy, and NONE of them throws this exception. I got lost at this moment - I do not know if there is an error, or if there is, how to track it.
If you are curious curious, this code is pyspeckit and the test does not work on line 20 of test_hr2421.py .
EDIT: Follow-up - I think this little snippet: np.seterr(invalid='raise') is called in the module that I imported, in particular pymc, and the transfer request has since prevented this change.
source share