Skip to content

BUG: Series.combine_first() changes int dtypes, but not Int (extension) dtypes #53700

Closed
@Dr-Irv

Description

@Dr-Irv

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

>>> import pandas as pd
>>> s1 = pd.Series([1, 2, 3], index=["A", "B", "C"])
>>> s2 = pd.Series([4, 6], index=["A", "C"])
>>> s1
A    1
B    2
C    3
dtype: int64
>>> s2
A    4
C    6
dtype: int64
>>> s2.combine_first(s1)
A    4.0
B    2.0
C    6.0
dtype: float64
>>> s2.convert_dtypes()
A    4
C    6
dtype: Int64
>>> s2.convert_dtypes().combine_first(s1.convert_dtypes())
A    4
B    2
C    6
dtype: Int64

Issue Description

In the example, the dtypes of the Series are int64 but when you do combine_first, the result has a dtype of float64.

If you use convert_dtypes() to change the types to Int64, then the dtype is preserved.

Expected Behavior

The int64 dtype should be preserved.

Installed Versions

show_details() didn't work!

pandas 2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closing CandidateMay be closeable, needs more eyeballs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions