Skip to content

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

Closed

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.

Activity

  1. Liam3851 commented on May 3, 2018

    @Liam3851

    Does not reproduce on Windows 7 under 1.14.2/Python 2.7.15. See my closure of #8230.

  2. galentx commented on May 5, 2018

    @galentx
    Author

    I'm afraid it DOES reproduce under my numpy 1.14.2/Python 2.7.15:

     Python 2.7.15 |Anaconda custom (64-bit)| (default, May  1 2018, 18:37:09) [MSC v.1500 64 bit (AMD64)] on win32
     Type "help", "copyright", "credits" or "license" for more information.
     >>> import sys
     >>> import numpy as np
     >>> x = np.float64([-2, -1, 0, 1, 2])
     >>> y = x.copy()
     >>> y[2] = np.nan
     >>> print 'sys.version:', sys.version
     sys.version: 2.7.15 |Anaconda custom (64-bit)| (default, May  1 2018, 18:37:09) [MSC v.1500 64 bit (AMD64)]
     >>> print 'np.version.version:', np.version.version
     np.version.version: 1.14.2
     >>> print 'np.sign(x):', np.sign(x)
     np.sign(x): [-1. -1.  0.  1.  1.]
     >>> print 'y:', y
     y: [-2. -1. nan  1.  2.]
     >>> print 'np.sign(y):', np.sign(y)
     np.sign(y):__main__:1: RuntimeWarning: invalid value encountered in sign
      [-1. -1. nan  1.  1.]
     >>>
    
  3. pepicello commented on Nov 6, 2019

    @pepicello

    I can report this also happens with Windows 64bit and numpy 1.16.4 / Python 3.7.4

  4. mhvk commented on Nov 17, 2019

    @mhvk
    Contributor

    We're seeing this too in our astropy testing - on windows only.

  5. fengluoqiuwu commented on Oct 27, 2024

    @fengluoqiuwu
    Contributor

    The warning doesn't occur in 2.2.0.dev0+git20241024.88a6a00, Python 3.12.7 with Windows64.

  6. mattip commented on Sep 25, 2025

    @mattip
    Member

    Seems to have been fixed somewhere between 1.16 and 2.2. Closing, please reopen if the issue reappears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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