Skip to content

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

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
Dr-Irv opened this issue Jun 16, 2023 · 3 comments
Closed
2 of 3 tasks
Labels
Closing Candidate May be closeable, needs more eyeballs

Comments

@Dr-Irv
Copy link
Contributor

Dr-Irv commented Jun 16, 2023

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

@Dr-Irv Dr-Irv added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 16, 2023
@Dr-Irv Dr-Irv changed the title BUG: Series.combine_first() changes int dtypes, but not Int dtypes BUG: Series.combine_first() changes int dtypes, but not Int (extension) dtypes Jun 16, 2023
@phofl
Copy link
Member

phofl commented Jun 16, 2023

Pretty sure there is a reindex happening under the hood which coerces the dtype. Investigations welcome

@lukemanley
Copy link
Member

This is fixed on main (#51777). I think this can be closed.

@lukemanley lukemanley added Closing Candidate May be closeable, needs more eyeballs and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 17, 2023
@Dr-Irv
Copy link
Contributor Author

Dr-Irv commented Jun 19, 2023

This is fixed on main (#51777). I think this can be closed.

Thanks @lukemanley . I agree.

@Dr-Irv Dr-Irv closed this as completed Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs
Projects
None yet
Development

No branches or pull requests

3 participants