Skip to content

combine_first changes datatype #28613

Closed
@mohitanand001

Description

@mohitanand001
df_1 = pd.DataFrame(data = {'A' : [1, 2, 3], 'B' : [4, 5, 6]})
df_2 = pd.DataFrame(data = {'A' : [1, 20, 30], 'B' : [40, 50, 60], 'C' : [12, 34, 65]})
df_1.combine_first(df_2).dtypes
A      int64
B      int64
C    float64
dtype: object

Problem description

The combine_first changes the datatype of the the column C to float64 from int64. Is this
an expected behavior

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit : None python : 3.7.1.final.0 python-bits : 64 OS : Windows OS-release : 10 machine : AMD64 processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : None.None

pandas : 0.25.0
numpy : 1.16.2
pytz : 2018.7
dateutil : 2.7.5
pip : 18.1
setuptools : 40.6.3
Cython : 0.29.2
pytest : 4.0.2
hypothesis : None
sphinx : 1.8.2
blosc : None
feather : 0.4.0
xlsxwriter : 1.1.2
lxml.etree : 4.2.5
html5lib : 1.0.1
pymysql : None
psycopg2 : 2.8.3 (dt dec pq3 ext lo64)
jinja2 : 2.10
IPython : 7.2.0
pandas_datareader: None
bs4 : 4.6.3
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.2.5
matplotlib : 3.0.2
numexpr : 2.6.8
odfpy : None
openpyxl : 2.5.12
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
s3fs : None
scipy : 1.1.0
sqlalchemy : 1.2.15
tables : 3.4.4
xarray : None
xlrd : 1.0.0
xlwt : 1.3.0
xlsxwriter : 1.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Dtype ConversionsUnexpected or buggy dtype conversionsNeeds TestsUnit test(s) needed to prevent regressionsReshapingConcat, Merge/Join, Stack/Unstack, Explodegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions