Skip to content
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

Nullable Int64 datatype is not preserved when used as index #30001

Closed
jfogelberg opened this issue Dec 3, 2019 · 2 comments
Closed

Nullable Int64 datatype is not preserved when used as index #30001

jfogelberg opened this issue Dec 3, 2019 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request ExtensionArray Extending pandas with custom dtypes or arrays.

Comments

@jfogelberg
Copy link

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({'a': [1, 2, None], 'b':[1, 2, 1]}, dtype=pd.Int64Dtype())
df.set_index('a').reset_index().dtypes

a float64
b Int64
dtype: object

Problem description

Nullable Int64 datatype is lost if the column is used as index.
This means that it is lost whenever we do a groupby followed by a reset_index and if we try to merge it with the original dataframe we get errors (at least if we try to merge int64 with Int64).

If the column contained NaNs it will be converted to float, if it did not contain NaNs it will be converted to int64 (not nullable).

Expected Output

a Int64
b Int64
dtype: object

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.24.2
pytest: 4.6.2
pip: 19.1.1
setuptools: 41.0.1
Cython: 0.29.10
numpy: 1.16.4
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.9.0
sphinx: None
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.1.0
openpyxl: None
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: 1.3.5
pymysql: None
psycopg2: None
jinja2: 2.10.3
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@jreback
Copy link
Contributor

jreback commented Dec 3, 2019

yes, see #22861

@jreback jreback closed this as completed Dec 3, 2019
@jreback jreback added Duplicate Report Duplicate issue or pull request ExtensionArray Extending pandas with custom dtypes or arrays. labels Dec 3, 2019
@jreback jreback added this to the No action milestone Dec 3, 2019
@jreback
Copy link
Contributor

jreback commented Dec 3, 2019

there is a PR, but needs work: #23223

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

No branches or pull requests

2 participants