Skip to content

Commit 362f2e2

Browse files
pambotjreback
authored andcommitted
CLN GH22985 Fixed interpolation with object error message (#23044)
1 parent db399c2 commit 362f2e2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pandas/core/generic.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6388,7 +6388,9 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
63886388

63896389
if _maybe_transposed_self._data.get_dtype_counts().get(
63906390
'object') == len(_maybe_transposed_self.T):
6391-
raise TypeError("Cannot interpolate with all NaNs.")
6391+
raise TypeError("Cannot interpolate with all object-dtype columns "
6392+
"in the DataFrame. Try setting at least one "
6393+
"column to a numeric dtype.")
63926394

63936395
# create/use the index
63946396
if method == 'linear':

pandas/tests/frame/test_missing.py

+13
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,19 @@ def test_interp_raise_on_only_mixed(self):
814814
with pytest.raises(TypeError):
815815
df.interpolate(axis=1)
816816

817+
def test_interp_raise_on_all_object_dtype(self):
818+
# GH 22985
819+
df = DataFrame({
820+
'A': [1, 2, 3],
821+
'B': [4, 5, 6]},
822+
dtype='object')
823+
with tm.assert_raises_regex(
824+
TypeError,
825+
"Cannot interpolate with all object-dtype columns "
826+
"in the DataFrame. Try setting at least one "
827+
"column to a numeric dtype."):
828+
df.interpolate()
829+
817830
def test_interp_inplace(self):
818831
df = DataFrame({'a': [1., 2., np.nan, 4.]})
819832
expected = DataFrame({'a': [1., 2., 3., 4.]})

0 commit comments

Comments
 (0)