Skip to content

FIX: series.fillna doesn't shallow copy if len(series) == 0 #32733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ Indexing
Missing
^^^^^^^

-
-
- 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`).


MultiIndex
^^^^^^^^^^
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6081,9 +6081,6 @@ def fillna(
downcast=downcast,
)
else:
if len(self._get_axis(axis)) == 0:
return self

if self.ndim == 1:
if isinstance(value, (dict, ABCSeries)):
value = create_series_with_explicit_dtype(
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/base/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,6 @@ def test_fillna(self, index_or_series_obj):
tm.assert_series_equal(obj, result)

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

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