Skip to content

Commit f59cbcb

Browse files
authored
BUG: Series.combine_first with reindex None->Nan (#62932)
1 parent 98b70f0 commit f59cbcb

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ Reshaping
11871187
- Bug in :meth:`DataFrame.join` inconsistently setting result index name (:issue:`55815`)
11881188
- Bug in :meth:`DataFrame.join` when a :class:`DataFrame` with a :class:`MultiIndex` would raise an ``AssertionError`` when :attr:`MultiIndex.names` contained ``None``. (:issue:`58721`)
11891189
- Bug in :meth:`DataFrame.merge` where merging on a column containing only ``NaN`` values resulted in an out-of-bounds array access (:issue:`59421`)
1190+
- Bug in :meth:`Series.combine_first` incorrectly replacing ``None`` entries with ``NaN`` (:issue:`58977`)
11901191
- Bug in :meth:`DataFrame.unstack` producing incorrect results when ``sort=False`` (:issue:`54987`, :issue:`55516`)
11911192
- Bug in :meth:`DataFrame.unstack` raising an error with indexes containing ``NaN`` with ``sort=False`` (:issue:`61221`)
11921193
- Bug in :meth:`DataFrame.merge` when merging two :class:`DataFrame` on ``intc`` or ``uintc`` types on Windows (:issue:`60091`, :issue:`58713`)

pandas/core/series.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
)
8888
from pandas.core.dtypes.dtypes import (
8989
ExtensionDtype,
90-
SparseDtype,
9190
)
9291
from pandas.core.dtypes.generic import (
9392
ABCDataFrame,
@@ -3254,9 +3253,6 @@ def combine_first(self, other) -> Series:
32543253
if self.dtype == other.dtype:
32553254
if self.index.equals(other.index):
32563255
return self.mask(self.isna(), other)
3257-
elif self._can_hold_na and not isinstance(self.dtype, SparseDtype):
3258-
this, other = self.align(other, join="outer")
3259-
return this.mask(this.isna(), other)
32603256

32613257
new_index = self.index.union(other.index)
32623258

pandas/tests/series/methods/test_combine_first.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,12 @@ def test_combine_mixed_timezone(self):
144144
),
145145
)
146146
tm.assert_series_equal(result, expected)
147+
148+
def test_combine_first_none_not_nan(self):
149+
# GH#58977
150+
s1 = Series([None, None, None], index=["a", "b", "c"])
151+
s2 = Series([None, None, None], index=["b", "c", "d"])
152+
153+
result = s1.combine_first(s2)
154+
expected = Series([None] * 4, index=["a", "b", "c", "d"])
155+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)