diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 858d2ba82a969..c6f7e6296bc13 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7749,11 +7749,6 @@ def interpolate( raise ValueError("'method' should be a string, not None.") obj, should_transpose = (self.T, True) if axis == 1 else (self, False) - # GH#53631 - if np.any(obj.dtypes == object): - raise TypeError( - f"{type(self).__name__} cannot interpolate with object dtype." - ) if isinstance(obj.index, MultiIndex) and method != "linear": raise ValueError( diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 468ec32ce7760..7be1d5d95ffdf 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -1388,12 +1388,10 @@ def interpolate( # If there are no NAs, then interpolate is a no-op return [self.copy(deep=False)] - # TODO(3.0): this case will not be reachable once GH#53638 is enforced if self.dtype == _dtype_obj: - # only deal with floats - # bc we already checked that can_hold_na, we don't have int dtype here - # test_interp_basic checks that we make a copy here - return [self.copy(deep=False)] + # GH#53631 + name = {1: "Series", 2: "DataFrame"}[self.ndim] + raise TypeError(f"{name} cannot interpolate with object dtype.") copy, refs = self._get_refs_and_copy(inplace) diff --git a/pandas/tests/series/methods/test_interpolate.py b/pandas/tests/series/methods/test_interpolate.py index c5df1fd498938..1008c2c87dc9e 100644 --- a/pandas/tests/series/methods/test_interpolate.py +++ b/pandas/tests/series/methods/test_interpolate.py @@ -790,11 +790,9 @@ def test_interpolate_unsorted_index(self, ascending, expected_values): def test_interpolate_asfreq_raises(self): ser = Series(["a", None, "b"], dtype=object) - msg2 = "Series cannot interpolate with object dtype" - msg = "Invalid fill method" - with pytest.raises(TypeError, match=msg2): - with pytest.raises(ValueError, match=msg): - ser.interpolate(method="asfreq") + msg = "Can not interpolate with method=asfreq" + with pytest.raises(ValueError, match=msg): + ser.interpolate(method="asfreq") def test_interpolate_fill_value(self): # GH#54920