From c5ed35845ea35e75fd16538090637f8b0a69cd72 Mon Sep 17 00:00:00 2001 From: Andreas Berneryd Date: Fri, 18 Aug 2017 11:21:51 +0200 Subject: [PATCH] BUG: fillna returns frame when inplace=True if value is a dict (#16156) --- doc/source/whatsnew/v0.21.0.txt | 2 +- pandas/core/generic.py | 3 ++- pandas/tests/frame/test_missing.py | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 85685ed7b430d..93d5c191a1d63 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -314,7 +314,7 @@ Conversion - Fix :func:`DataFrame.memory_usage` to support PyPy. Objects on PyPy do not have a fixed size, so an approximation is used instead (:issue:`17228`) - Fixed the return type of ``IntervalIndex.is_non_overlapping_monotonic`` to be a Python ``bool`` for consistency with similar attributes/methods. Previously returned a ``numpy.bool_``. (:issue:`17237`) - Bug in ``IntervalIndex.is_non_overlapping_monotonic`` when intervals are closed on both sides and overlap at a point (:issue:`16560`) - +- Bug in :func:`Series.fillna` returns frame when ``inplace=True`` and ``value`` is dict (:issue:`16156`) Indexing ^^^^^^^^ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 5a7f37bba91aa..6480d75a61859 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4054,7 +4054,8 @@ def fillna(self, value=None, method=None, axis=None, inplace=False, continue obj = result[k] obj.fillna(v, limit=limit, inplace=True, downcast=downcast) - return result + return result if not inplace else None + elif not is_list_like(value): new_data = self._data.fillna(value=value, limit=limit, inplace=inplace, diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index 77f0357685cab..ebd15b3180a33 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -407,6 +407,9 @@ def test_fillna_inplace(self): df.fillna(value=0, inplace=True) tm.assert_frame_equal(df, expected) + expected = df.fillna(value={0: 0}, inplace=True) + assert expected is None + df[1][:4] = np.nan df[3][-4:] = np.nan expected = df.fillna(method='ffill')