Skip to content

Commit cf260da

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

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-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

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

0 commit comments

Comments
 (0)