Skip to content

Commit fefadcb

Browse files
combine_first's combiner must preserve EA dtypes
1 parent ef662a0 commit fefadcb

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

pandas/core/frame.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9026,9 +9026,7 @@ def combine(
90269026
2 NaN 3.0 1.0
90279027
"""
90289028

9029-
# GH#60128 Prevent lossy conversion of wide integers
9030-
# by proactively promoting them to their nullable versions
9031-
# because an outer align will force a round trip through float64.
9029+
# GH#60128 Prevent lossy conversion of wide integers to float64.
90329030
def _promote_wide_ints(df: DataFrame) -> DataFrame:
90339031
"""Promotes int64/uint64 columns to their nullable versions."""
90349032
cast_map: dict[str, str] = {}
@@ -9190,20 +9188,10 @@ def combine_first(self, other: DataFrame) -> DataFrame:
91909188
1 0.0 3.0 1.0
91919189
2 NaN 3.0 1.0
91929190
"""
9193-
from pandas.core.computation import expressions
91949191

91959192
def combiner(x: Series, y: Series):
9196-
mask = x.isna()._values
9197-
9198-
x_values = x._values
9199-
y_values = y._values
9200-
9201-
# If the column y in other DataFrame is not in first DataFrame,
9202-
# just return y_values.
9203-
if y.name not in self.columns:
9204-
return y_values
9205-
9206-
return expressions.where(mask, y_values, x_values)
9193+
# GH#60128 The combiner must preserve EA dtypes
9194+
return y if y.name not in self.columns else y.where(x.isna(), x)
92079195

92089196
if len(other) == 0:
92099197
combined = self.reindex(

0 commit comments

Comments
 (0)