Skip to content

Commit a17527b

Browse files
lukemanleymeeseeksmachine
authored andcommitted
Backport PR pandas-dev#57034: REGR: perf regression in Series.combine_first
1 parent 2df78e8 commit a17527b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

doc/source/whatsnew/v2.2.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ including other versions of pandas.
1313

1414
Fixed regressions
1515
~~~~~~~~~~~~~~~~~
16+
- Fixed performance regression in :meth:`Series.combine_first` (:issue:`55845`)
1617
- Fixed regression in :func:`merge_ordered` raising ``TypeError`` for ``fill_method="ffill"`` and ``how="left"`` (:issue:`57010`)
1718
- Fixed regression in :meth:`Series.pct_change` raising a ``ValueError`` for an empty :class:`Series` (:issue:`57056`)
1819

pandas/core/series.py

+8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
from pandas.core.dtypes.dtypes import (
8787
CategoricalDtype,
8888
ExtensionDtype,
89+
SparseDtype,
8990
)
9091
from pandas.core.dtypes.generic import (
9192
ABCDataFrame,
@@ -3510,6 +3511,13 @@ def combine_first(self, other) -> Series:
35103511
"""
35113512
from pandas.core.reshape.concat import concat
35123513

3514+
if self.dtype == other.dtype:
3515+
if self.index.equals(other.index):
3516+
return self.mask(self.isna(), other)
3517+
elif self._can_hold_na and not isinstance(self.dtype, SparseDtype):
3518+
this, other = self.align(other, join="outer")
3519+
return this.mask(this.isna(), other)
3520+
35133521
new_index = self.index.union(other.index)
35143522

35153523
this = self

0 commit comments

Comments
 (0)