From 47bc7baf1ed4bb5f00812b7adcf08441c340e550 Mon Sep 17 00:00:00 2001 From: sanderland <48946947+sanderland@users.noreply.github.com> Date: Tue, 4 Aug 2020 14:50:56 +0200 Subject: [PATCH 1/6] Fix interpolation on empty dataframe Interpolation on an empty dataframe broke in 1.1 due to a change in how 'all columns are objects' is checked (specifically all(empty set) is True, while before dtype count object = None was checked against size = 0). This is a complex function and I'm not sure what the proper fix is, suggesting to keep the empty check out of the rest of the logic. --- pandas/core/generic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e46fde1f59f16..10b44c65f3beb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6799,6 +6799,9 @@ def interpolate( obj = self.T if should_transpose else self + if obj.empty: + return self + if method not in fillna_methods: axis = self._info_axis_number From 2b17cb2a840fa654e50871e89b3ceddc84d4a2f6 Mon Sep 17 00:00:00 2001 From: sanderland <48946947+sanderland@users.noreply.github.com> Date: Tue, 4 Aug 2020 14:53:26 +0200 Subject: [PATCH 2/6] Update generic.py --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 10b44c65f3beb..fa791bed6c97c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6801,7 +6801,7 @@ def interpolate( if obj.empty: return self - + if method not in fillna_methods: axis = self._info_axis_number From 1676a4320c1470f09f7dbded59ac6aec576b69b0 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Wed, 5 Aug 2020 09:55:05 +0200 Subject: [PATCH 3/6] add test --- pandas/tests/frame/methods/test_interpolate.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index ddb5723e7bd3e..2ae0b444ff04e 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -34,6 +34,10 @@ def test_interp_basic(self): expected.loc[5, "B"] = 9 tm.assert_frame_equal(result, expected) + def test_interp_empty(self): + df = DataFrame() + tm.assert_frame_equal(df, df.interpolate()) + def test_interp_bad_method(self): df = DataFrame( { From 5844c894e4cfb29144ea9fc0fdfe44916bec1052 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Fri, 7 Aug 2020 10:44:00 +0200 Subject: [PATCH 4/6] whatsnew entry, test fix --- doc/source/whatsnew/v1.1.1.rst | 2 +- pandas/tests/frame/methods/test_interpolate.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.1.1.rst b/doc/source/whatsnew/v1.1.1.rst index 6a327a4fc732f..68b5107026b77 100644 --- a/doc/source/whatsnew/v1.1.1.rst +++ b/doc/source/whatsnew/v1.1.1.rst @@ -16,7 +16,7 @@ Fixed regressions ~~~~~~~~~~~~~~~~~ - Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`). -- +- Fixed regression where :func:`interpolate` would raise a ``TypeError`` when the dataframe was empty (:issue:`35598`). - .. --------------------------------------------------------------------------- diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index 2ae0b444ff04e..18ce578281baf 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -36,7 +36,9 @@ def test_interp_basic(self): def test_interp_empty(self): df = DataFrame() - tm.assert_frame_equal(df, df.interpolate()) + result = df.interpolate() + expected = df + tm.assert_frame_equal(result, expected) def test_interp_bad_method(self): df = DataFrame( From 6b5245b19a16bd352e62923ab33f5688a53d9d17 Mon Sep 17 00:00:00 2001 From: sanderland <48946947+sanderland@users.noreply.github.com> Date: Fri, 7 Aug 2020 21:36:15 +0200 Subject: [PATCH 5/6] Update pandas/tests/frame/methods/test_interpolate.py Co-authored-by: Simon Hawkins --- pandas/tests/frame/methods/test_interpolate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/frame/methods/test_interpolate.py b/pandas/tests/frame/methods/test_interpolate.py index 18ce578281baf..3c9d79397e4bd 100644 --- a/pandas/tests/frame/methods/test_interpolate.py +++ b/pandas/tests/frame/methods/test_interpolate.py @@ -35,6 +35,7 @@ def test_interp_basic(self): tm.assert_frame_equal(result, expected) def test_interp_empty(self): + # https://github.com/pandas-dev/pandas/issues/35598 df = DataFrame() result = df.interpolate() expected = df From ad4eaa769224ff2e69eaa5ce1af96bffa7431c9d Mon Sep 17 00:00:00 2001 From: sanderland <48946947+sanderland@users.noreply.github.com> Date: Fri, 7 Aug 2020 21:36:47 +0200 Subject: [PATCH 6/6] Update doc/source/whatsnew/v1.1.1.rst Co-authored-by: Simon Hawkins --- doc/source/whatsnew/v1.1.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.1.rst b/doc/source/whatsnew/v1.1.1.rst index 746a8e13c9f5f..8c3fb5f19dcb0 100644 --- a/doc/source/whatsnew/v1.1.1.rst +++ b/doc/source/whatsnew/v1.1.1.rst @@ -17,7 +17,7 @@ Fixed regressions - Fixed regression where :func:`read_csv` would raise a ``ValueError`` when ``pandas.options.mode.use_inf_as_na`` was set to ``True`` (:issue:`35493`). - Fixed regression in :class:`pandas.core.groupby.RollingGroupby` where column selection was ignored (:issue:`35486`) -- Fixed regression where :func:`interpolate` would raise a ``TypeError`` when the dataframe was empty (:issue:`35598`). +- Fixed regression where :meth:`DataFrame.interpolate` would raise a ``TypeError`` when the :class:`DataFrame` was empty (:issue:`35598`). .. ---------------------------------------------------------------------------