Skip to content

Commit cffc591

Browse files
author
Pamela Wu
committed
CLN GH22985 Fixed interpolation with object error message
1 parent ce1f81f commit cffc591

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas/core/generic.py

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

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

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

pandas/tests/frame/test_missing.py

+10
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,16 @@ 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+
df = DataFrame({'A': [1, 2, 3],
819+
'B': [4, 5, 6]},
820+
dtype='object')
821+
with tm.assert_raises_regex(TypeError,
822+
"Cannot interpolate with all object-dtype columns "
823+
"in the DataFrame. Try setting at least one "
824+
"column to a numeric dtype."):
825+
df.interpolate()
826+
817827
def test_interp_inplace(self):
818828
df = DataFrame({'a': [1., 2., np.nan, 4.]})
819829
expected = DataFrame({'a': [1., 2., 3., 4.]})

0 commit comments

Comments
 (0)