From e139c2a105ce39912ba5c3609833c1b0700a63b2 Mon Sep 17 00:00:00 2001 From: Martin Winkel Date: Sun, 15 Mar 2020 18:13:43 +0100 Subject: [PATCH 1/3] [#32543] obj.fillna(fill_value) doesn't shallow copy if obj is an empty Series --- pandas/core/generic.py | 3 --- pandas/tests/base/test_ops.py | 3 --- 2 files changed, 6 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8d56311331d4d..88c2ea810b3b6 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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( diff --git a/pandas/tests/base/test_ops.py b/pandas/tests/base/test_ops.py index 5a78e5d6352a9..9f94a74fbb581 100644 --- a/pandas/tests/base/test_ops.py +++ b/pandas/tests/base/test_ops.py @@ -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]) From 93797f480e1e33981907cbd81796e2d3adadb046 Mon Sep 17 00:00:00 2001 From: Martin Winkel Date: Sun, 15 Mar 2020 20:07:00 +0100 Subject: [PATCH 2/3] added whatsnew entry --- doc/source/whatsnew/v1.1.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 21e59805fa143..80086c091be6d 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -231,6 +231,7 @@ Performance improvements Bug fixes ~~~~~~~~~ +- 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`). Categorical ^^^^^^^^^^^ From bc5a3f20aba7632a3d4491837e227f090af747ce Mon Sep 17 00:00:00 2001 From: Martin Winkel Date: Mon, 16 Mar 2020 09:11:00 +0100 Subject: [PATCH 3/3] updated whatsnew entry --- doc/source/whatsnew/v1.1.0.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 80086c091be6d..fb45a9390e1d8 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -231,7 +231,6 @@ Performance improvements Bug fixes ~~~~~~~~~ -- 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`). Categorical ^^^^^^^^^^^ @@ -304,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 ^^^^^^^^^^