Skip to content

Commit d928a5c

Browse files
authored
REGR: perf regression in Series.combine_first (#57034)
* fix perf regression in Series.combine_first * fix
1 parent 7368686 commit d928a5c

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
@@ -87,6 +87,7 @@
8787
from pandas.core.dtypes.dtypes import (
8888
CategoricalDtype,
8989
ExtensionDtype,
90+
SparseDtype,
9091
)
9192
from pandas.core.dtypes.generic import (
9293
ABCDataFrame,
@@ -3514,6 +3515,13 @@ def combine_first(self, other) -> Series:
35143515
"""
35153516
from pandas.core.reshape.concat import concat
35163517

3518+
if self.dtype == other.dtype:
3519+
if self.index.equals(other.index):
3520+
return self.mask(self.isna(), other)
3521+
elif self._can_hold_na and not isinstance(self.dtype, SparseDtype):
3522+
this, other = self.align(other, join="outer")
3523+
return this.mask(this.isna(), other)
3524+
35173525
new_index = self.index.union(other.index)
35183526

35193527
this = self

0 commit comments

Comments
 (0)