Skip to content

BUG: nan's yield warnings in sign, greater_equal, and elsewhere #8945

@galentx

Description

@galentx

I believe sign should handle NaN's silently, but it yields a warning:

Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 19 2016, 13:29:36) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy as np
>>> x = np.float64([-2, -1, 0, 1, 2])
>>> np.sign(x)
array([-1., -1.,  0.,  1.,  1.])
>>> y = x.copy()
>>> y[2] = np.nan
>>> y
array([ -2.,  -1.,  nan,   1.,   2.])
>>> np.sign(y)
__main__:1: RuntimeWarning: invalid value encountered in sign
array([ -1.,  -1.,  nan,   1.,   1.])
>>> np.version.version
'1.12.1'

I also see similar warnings with greater_equal, less_equal, and absolute in a call to matplotlib symlog:

C:\Anaconda2\lib\site-packages\matplotlib\scale.py:290: RuntimeWarning: invalid value encountered in sign
  sign = np.sign(a)
C:\Anaconda2\lib\site-packages\numpy\ma\core.py:2123: RuntimeWarning: invalid value encountered in greater_equal
  condition = (xf >= v1) & (xf <= v2)
C:\Anaconda2\lib\site-packages\numpy\ma\core.py:2123: RuntimeWarning: invalid value encountered in less_equal
  condition = (xf >= v1) & (xf <= v2)
C:\Anaconda2\lib\site-packages\matplotlib\scale.py:297: RuntimeWarning: invalid value encountered in absolute
  ma.log(np.abs(masked) / self.linthresh) / self._log_base)

Windows 7 x64
Anaconda 4.3.1+ (custom to bring in np 1.12)
Python 2.7.13
numpy 1.12.1

This may be related to #8230, which suggests this is unique to Windows and Python 2.7, and #7440. The latter suggests it is a 32-bit problem but my environment is 64-bit. I don't think this was an issue with an earlier version of numpy, but I'm not sure of the prior version I used. It couldn't be more than a couple of years old.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions