Skip to content

CLN: move raising TypeError for interpolate with object dtype to Block #58083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/series/methods/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down