-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REGR: ValueError: cannot convert float NaN to integer - on dataframe.reset_index() in pandas 1.1.0 #35606
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
can you post a small code sample of this (i.e bug arising using the pandas public API) |
Sure. import pandas as pd
import datetime
df = pd.DataFrame({'a': [datetime.date(2020, 7, 20), datetime.date(2020, 7, 20)], 'b': [3, 4], 'c': [2.0, 3.0], 'd': [5, 4]})
df = df.set_index(['a', 'b'])
df = df[df['c'] == 1]
df.reset_index() |
Thanks @ndhansen for the example. so this issue is that there are unused codes in the MultiIndex
and this was working in 1.0.5
|
hmm #35111 efcf4b4 is the first bad commit
|
changing title to make issue more discoverable |
construct_1d_arraylike_from_scalar
does not handle NaT correctly
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Results in:
Problem description
This is a problem was found when calling
reset_index
on a MultiIndex Dataframe with an index containing datetime information. The expected behaviour would be that it would return an array of NaTs, which ironically only happens if you pass itnp.NaN
.I'm not familiar with the source code of numpy, so I can only speculate on how to fix it, but I would assume we would need special handling for time values, so we fill time arrays with
np.NaN
s instead ofpandas._libs.tslibs.nattype.NaTType
s.Expected Output
array(['NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT', 'NaT'], dtype=datetime64)
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.8.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.7.9-1-MANJARO
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.0.5
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0
Cython : 0.29.21
pytest : 5.4.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.5.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: 0.10.0dev0
bs4 : 4.9.1
bottleneck : 1.3.2
fastparquet : None
gcsfs : None
lxml.etree : 4.5.2
matplotlib : 3.3.0
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.4.3
pyxlsb : None
s3fs : None
scipy : 1.5.1
sqlalchemy : 1.3.17
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: