Note that there are some explanatory texts on larger screens.

plurals
  1. POnumpy FloatingPointError: invalid value encountered in subtract - not reproducible?
    primarykey
    data
    text
    <p>I'm encountering <code>FloatingPointError: invalid value encountered in subtract</code> in a piece of test code. The exception started being raised without any changes being made in the code itself, so I'm having a great deal of trouble understanding it.</p> <p>My question: What causes the <code>invalid value encountered in subtract</code> exception? Why would it behave differently on different installs of python+numpy?</p> <p>DETAILS:</p> <p>This MWE does <em>not</em> raise a <code>FloatingPointError</code>:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; np.__version__ '1.6.1' &gt;&gt;&gt; x = np.arange(5,dtype='float64') &gt;&gt;&gt; y = np.ones(5,dtype='float64') &gt;&gt;&gt; x[2]=np.nan &gt;&gt;&gt; x-y # array([ -1., 0., nan, 2., 3.]) </code></pre> <p>However, deep within a piece of code, I subtract two <code>np.float64</code> <code>ndarray</code> objects, and get a floating point exception. The arrays causing the exception contain some pretty enormous and tiny numbers (e.g., 1e307 and 1e-307) and some <code>nan</code>s, but I haven't made any combination of these numbers result in an exception testing on my own.</p> <p>Much more disturbingly, I have a large grid of Jenkins tests running the exact same code with many versions of numpy, matplotlib, python, and scipy, and NONE of them raise this exception. I'm lost at this point - I don't know if there is a bug, or if there is, how to track it down. </p> <p>In case you're morbidly curious, the code in question is <a href="http://pyspeckit.bitbucket.org" rel="nofollow">pyspeckit</a> and the test is failing on line 20 of <code>test_hr2421.py</code>.</p> <p>EDIT: Follow-up - I think this little snippet: <code>np.seterr(invalid='raise')</code> was being called in a module I was importing, specifically pymc, and a pull request has since prevented this change from being made.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload