Skip to content

Commit 33af3b8

Browse files
authored
CLN: move raising TypeError for interpolate with object dtype to Block (pandas-dev#58083)
* move raising for interpolate with object dtype from NDFrame to Block * correct msg in test_interpolate_cannot_with_object_dtype * correct the exception message and the comments
1 parent 19aaf40 commit 33af3b8

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

pandas/core/generic.py

-5
Original file line numberDiff line numberDiff line change
@@ -7718,11 +7718,6 @@ def interpolate(
77187718
raise ValueError("'method' should be a string, not None.")
77197719

77207720
obj, should_transpose = (self.T, True) if axis == 1 else (self, False)
7721-
# GH#53631
7722-
if np.any(obj.dtypes == object):
7723-
raise TypeError(
7724-
f"{type(self).__name__} cannot interpolate with object dtype."
7725-
)
77267721

77277722
if isinstance(obj.index, MultiIndex) and method != "linear":
77287723
raise ValueError(

pandas/core/internals/blocks.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1388,12 +1388,10 @@ def interpolate(
13881388
# If there are no NAs, then interpolate is a no-op
13891389
return [self.copy(deep=False)]
13901390

1391-
# TODO(3.0): this case will not be reachable once GH#53638 is enforced
13921391
if self.dtype == _dtype_obj:
1393-
# only deal with floats
1394-
# bc we already checked that can_hold_na, we don't have int dtype here
1395-
# test_interp_basic checks that we make a copy here
1396-
return [self.copy(deep=False)]
1392+
# GH#53631
1393+
name = {1: "Series", 2: "DataFrame"}[self.ndim]
1394+
raise TypeError(f"{name} cannot interpolate with object dtype.")
13971395

13981396
copy, refs = self._get_refs_and_copy(inplace)
13991397

pandas/tests/series/methods/test_interpolate.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,9 @@ def test_interpolate_unsorted_index(self, ascending, expected_values):
790790

791791
def test_interpolate_asfreq_raises(self):
792792
ser = Series(["a", None, "b"], dtype=object)
793-
msg2 = "Series cannot interpolate with object dtype"
794-
msg = "Invalid fill method"
795-
with pytest.raises(TypeError, match=msg2):
796-
with pytest.raises(ValueError, match=msg):
797-
ser.interpolate(method="asfreq")
793+
msg = "Can not interpolate with method=asfreq"
794+
with pytest.raises(ValueError, match=msg):
795+
ser.interpolate(method="asfreq")
798796

799797
def test_interpolate_fill_value(self):
800798
# GH#54920

0 commit comments

Comments
 (0)