Skip to content

Commit 2b17609

Browse files
FIX: series.fillna doesn't shallow copy if len(series) == 0 (#32733)
1 parent 7514192 commit 2b17609

File tree

3 files changed

+2
-8
lines changed

3 files changed

+2
-8
lines changed

doc/source/whatsnew/v1.1.0.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ Indexing
305305
Missing
306306
^^^^^^^
307307

308-
-
309-
-
308+
- Calling :meth:`fillna` on an empty Series now correctly returns a shallow copied object. The behaviour is now consistent with :class:`Index`, :class:`DataFrame` and a non-empty :class:`Series` (:issue:`32543`).
309+
310310

311311
MultiIndex
312312
^^^^^^^^^^

pandas/core/generic.py

-3
Original file line numberDiff line numberDiff line change
@@ -6081,9 +6081,6 @@ def fillna(
60816081
downcast=downcast,
60826082
)
60836083
else:
6084-
if len(self._get_axis(axis)) == 0:
6085-
return self
6086-
60876084
if self.ndim == 1:
60886085
if isinstance(value, (dict, ABCSeries)):
60896086
value = create_series_with_explicit_dtype(

pandas/tests/base/test_ops.py

-3
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,6 @@ def test_fillna(self, index_or_series_obj):
562562
tm.assert_series_equal(obj, result)
563563

564564
# check shallow_copied
565-
if isinstance(obj, Series) and len(obj) == 0:
566-
# TODO: GH-32543
567-
pytest.xfail("Shallow copy for empty Series is bugged")
568565
assert obj is not result
569566

570567
@pytest.mark.parametrize("null_obj", [np.nan, None])

0 commit comments

Comments
 (0)