Skip to content

BUG: outer/right merging on two "Int64" columns results in an "int64" column #41197

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

Closed
2 of 3 tasks
kpflugshaupt opened this issue Apr 28, 2021 · 1 comment
Closed
2 of 3 tasks
Labels
Bug Duplicate Report Duplicate issue or pull request

Comments

@kpflugshaupt
Copy link
Contributor

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


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd

# Outer merge on two "Int64" columns casts the joining column to "int64"
df1 = pd.DataFrame(dict(nr=[1,2])).astype("Int64")
df2 = pd.DataFrame(dict(nr=[2,3])).astype("Int64")
pd.merge(df1, df2, on="nr", how="outer").dtypes
# nr    int64
# dtype: object

# Inner merge is OK
pd.merge(df1, df2, on="nr", how="inner").dtypes
# nr    Int64
# dtype: object

# Left merge is OK
pd.merge(df1, df2, on="nr", how="left").dtypes
# nr    Int64
# dtype: object

# Right merge also casts to "int64"
pd.merge(df1, df2, on="nr", how="right").dtypes
# nr    int64
# dtype: object

Problem description

"Int64" columns lose their data type and are converted to "int64" when used as joining column in an outer or right merge.
This does not seem to happen for inner and left merges.

Expected Output

"Int64" columns should retain their dtype during merge operations.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2cb9652
python : 3.8.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : German_Switzerland.1252
pandas : 1.2.4
numpy : 1.20.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1
setuptools : 51.0.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.0
pyxlsb : None
s3fs : None
scipy : 1.6.3
sqlalchemy : 1.4.0b1
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@kpflugshaupt kpflugshaupt added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 28, 2021
@mzeitlin11
Copy link
Member

Thanks for the report @kpflugshaupt! Think this is the same underlying cause as #40073, so will close in favor of that. Contributions welcome there!

@mzeitlin11 mzeitlin11 added Duplicate Report Duplicate issue or pull request and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Duplicate Report Duplicate issue or pull request
Projects
None yet
Development

No branches or pull requests

2 participants