-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: numpy RuntimeWarning with Series.round() #14197
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
Comments
need to mask the values before rounding (iow not null ones) |
I'll have a look and submit a PR |
I can't seem to replicate the warning.. Running 2.7.12 and the latest dev version of pandas |
hmm, maybe this is on an older version of numpy. @xflr6 can you |
Sure: >>> import pandas as pd
>>> pd.Series([pd.np.nan]).round()
Warning (from warnings module):
File "C:\Program Files\Python27\lib\site-packages\pandas\core\series.py", line 1340
result = _values_from_object(self).round(decimals)
RuntimeWarning: invalid value encountered in rint
0 NaN
dtype: float64
>>> pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.12.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: de_DE.cp1252
pandas: 0.19.0rc1
nose: 1.3.7
pip: 8.1.2
setuptools: 27.2.0
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.0
statsmodels: 0.8.0rc1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: None
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.4.0
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: 3.6.4
bs4: 4.5.1
html5lib: 0.999999999
httplib2: 0.9.2
apiclient: None
sqlalchemy: 1.0.15
pymysql: None
psycopg2: 2.6.2 (dt dec pq3 ext lo64)
jinja2: 2.8
boto: None
pandas_datareader: None In some environments, warnings are silenced, try this before: >>> import warnings
>>> warnings.simplefilter('error') |
Seems to be a Windows-specific upstream issue: numpy/numpy#7882 >>> import numpy as np
>>> np.ma.masked_invalid([np.nan]).round()
Warning (from warnings module):
File "C:\Program Files\Python27\lib\site-packages\numpy\ma\core.py", line 5192
result = self._data.round(decimals=decimals, out=out).view(type(self))
RuntimeWarning: invalid value encountered in rint
masked_array(data = [--],
mask = [ True],
fill_value = 1e+20) >>> np.rint(np.nan)
Warning (from warnings module):
File "__main__", line 2
RuntimeWarning: invalid value encountered in rint
nan |
Correct me if I'm wrong, but doesn't Pandas usually ignore NA values in most calculations? So if you're trying to do some math, like rounding, what comes in as an NA would go out as an NA. Not sure why a warning is necessary here when it isn't necessary for multiplication, division, etc. |
but hats exactly the point; pandas needs a change to mask these values before sending to numpy; pull requests are welcome |
I cannot reproduce this error at HEAD. is it still open? |
Still open for me on Python 2, not on Python 3 though, see below. In [1]: import pandas as pd
In [2]: import warnings
...: warnings.simplefilter('error')
...: pd.Series([pd.np.nan]).round()
RuntimeWarningTraceback (most recent call last)
<ipython-input-2-0aec18ee80a1> in <module>()
1 import warnings
2 warnings.simplefilter('error')
----> 3 pd.Series([pd.np.nan]).round()
c:\programme\python27\lib\site-packages\pandas\core\series.pyc in round(self, decimals, *args, **kwargs)
1826 """
1827 nv.validate_round(args, kwargs)
-> 1828 result = com._values_from_object(self).round(decimals)
1829 result = self._constructor(result, index=self.index).__finalize__(self)
1830
RuntimeWarning: invalid value encountered in rint
In [3]: pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.15.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.23.3
pytest: 3.6.3
pip: 10.0.1
setuptools: None
Cython: 0.28.4
numpy: 1.15.0rc1
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 5.7.0
sphinx: 1.7.5
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: None
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.9
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: 0.5.0
pandas_datareader: None In [1]: import pandas as pd
...: import warnings
...: warnings.simplefilter('error')
...: pd.Series([pd.np.nan]).round()
Out[1]:
0 NaN
dtype: float64
In [2]: pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.7.0.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.23.3
pytest: 3.6.3
pip: 10.0.1
setuptools: None
Cython: 0.28.4
numpy: 1.15.0rc1
scipy: 1.1.0
pyarrow: None
xarray: None
IPython: 6.4.0
sphinx: 1.7.5
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: None
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: 2.7.5 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: 0.4.1
pandas_datareader: None |
if we add a test and skip for py2, could we close this issue? |
is this still showing in master? i thought this was fixed a long time ago |
on py2 windows, pandas 0.24.1.. Python 2.7.15 |Anaconda, Inc.| (default, Feb 21 2019, 11:55:13) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> pd.__version__
u'0.24.1'
>>> import warnings
>>> warnings.simplefilter('error')
>>> pd.Series([pd.np.nan]).round()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\simon\Anaconda3\envs\pandas-dev2\lib\site-packages\pandas\core\series.py", line 1999, in round
result = com.values_from_object(self).round(decimals)
RuntimeWarning: invalid value encountered in rint i've not got a build env set for py2 so can't check master. |
ok i think the problem is that we need to change how round is implemented alternatively u can call the numpy function and suppress the warning |
but if it's just py2, then moving forward this is a won't fix? so just test for py3 and close issue? |
yes that’s fine - is there a warning on py3? |
works on my machine! if we add a test we'll know if there's an issue with other platforms. |
Maybe needs wrapping in
numpy.errstate
(in pandas)?Same for
DataFrame.round()
.The text was updated successfully, but these errors were encountered: