10000 BUG: nan's yield warnings in sign, greater_equal, and elsewhere · Issue #8945 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
galentx opened this issue Apr 14, 2017 · 6 comments
Open

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

galentx opened this issue Apr 14, 2017 · 6 comments

Comments

@galentx
Copy link
galentx commented Apr 14, 2017

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.

@Liam3851
Copy link
Liam3851 commented May 3, 2018

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

@galentx
Copy link
Author
galentx commented May 5, 2018

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.]
 >>>

@ghost
Copy link
ghost commented Oct 20, 2018

I concur that sign should not flag nan's since the docs explain it returns nan for nan input.

@pepicello
Copy link

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

@mhvk
Copy link
Contributor
mhvk commented Nov 17, 2019

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

pllim added a commit to pllim/astropy that referenced this issue Nov 17, 2019
Remove unused code as follow up of astropy#9582

Handle failures cased by numpy/numpy#8945
maxnoe pushed a commit to maxnoe/astropy that referenced this issue Jan 6, 2020
Remove unused code as follow up of astropy#9582

Handle failures cased by numpy/numpy#8945
@fengluoqiuwu
Copy link
Contributor

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

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

No branches or pull requests

5 participants
0