[Numpy-discussion] Should abs([nan]) be supported?
Travis Oliphant
travis at continuum.io
Tue Sep 4 23:38:41 EDT 2012
There is an error context that controls how floating point signals are handled. There is a separate control for underflow, overflow, divide by zero, and invalid. IIRC, it was decided on this list a while ago to make the default ignore for underflow and warning for overflow, invalid and divide by zero.
However, an oversight pushed versions of NumPy where all the error handlers where set to "ignore" and this test was probably written then. I think the test should be changed to check for RuntimeWarning on some of the cases. This might take a little work as it looks like the code uses generators across multiple tests and would have to be changed to handle expecting warnings.
Alternatively, the error context can be set before the test runs and then restored afterwords:
olderr = np.seterr(invalid='ignore')
abs(a)
np.seterr(**olderr)
or, using an errstate context ---
with np.errstate(invalid='ignore'):
abs(a)
-Travis
On Sep 4, 2012, at 6:24 PM, Ondřej Čertík wrote:
> Hi,
>
> When running the test suite, there are problems of this kind:
>
> https://github.com/numpy/numpy/issues/394
>
> which then causes for example the Debian buildbots tests to fail
> (https://github.com/numpy/numpy/issues/406).
> The problem is really simple:
>
>
>>>> 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.])
>
>
> See the issue #394 for detailed explanation why "nan" is being passed
> to abs(). Now the question is, what should the right fix be?
>
> 1) Should the runtime warning be disabled?
>
> 2) Should the tests be reworked, so that "nan" is not tested in allclose()?
>
> 3) Should abs() be fixed to not emit the warning?
>
> 4) Should the test suite be somehow fixed not to fail if there are
> runtime warnings?
>
> Let me know which direction we should go.
>
> Thanks,
> Ondrej
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list