From fe13f5b8e336202bc9e8ed339b3bf6a1e4ec9dca Mon Sep 17 00:00:00 2001 From: Pamela Wu Date: Mon, 8 Oct 2018 10:10:19 -0400 Subject: [PATCH] CLN GH22985 Fixed interpolation with object error message --- pandas/core/generic.py | 4 +++- pandas/tests/frame/test_missing.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 8de52fbfa79f0..ce70e3ce56c08 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -6387,7 +6387,9 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False, if _maybe_transposed_self._data.get_dtype_counts().get( 'object') == len(_maybe_transposed_self.T): - raise TypeError("Cannot interpolate with all NaNs.") + raise TypeError("Cannot interpolate with all object-dtype columns " + "in the DataFrame. Try setting at least one " + "column to a numeric dtype.") # create/use the index if method == 'linear': diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index 136299a4b81be..9d1bd9e9a0234 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -814,6 +814,19 @@ def test_interp_raise_on_only_mixed(self): with pytest.raises(TypeError): df.interpolate(axis=1) + def test_interp_raise_on_all_object_dtype(self): + # GH 22985 + df = DataFrame({ + 'A': [1, 2, 3], + 'B': [4, 5, 6]}, + dtype='object') + with tm.assert_raises_regex( + TypeError, + "Cannot interpolate with all object-dtype columns " + "in the DataFrame. Try setting at least one " + "column to a numeric dtype."): + df.interpolate() + def test_interp_inplace(self): df = DataFrame({'a': [1., 2., np.nan, 4.]}) expected = DataFrame({'a': [1., 2., 3., 4.]})