Skip to content

Commit 3714ff5

Browse files
committed
TST(string dtype): Resolve xfail for interpolate
1 parent 8fbe6ac commit 3714ff5

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,7 @@ def interpolate(
21602160
"""
21612161
# NB: we return type(self) even if copy=False
21622162
if not self.dtype._is_numeric:
2163-
raise ValueError("Values must be numeric.")
2163+
raise TypeError(f"Cannot interpolate with {self.dtype} dtype")
21642164

21652165
if (
21662166
not pa_version_under13p0

pandas/tests/frame/methods/test_interpolate.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ def test_interpolate_inplace(self, frame_or_series, request):
6464
assert np.shares_memory(orig, obj.values)
6565
assert orig.squeeze()[1] == 1.5
6666

67-
# TODO(infer_string) raise proper TypeError in case of string dtype
68-
@pytest.mark.xfail(
69-
using_string_dtype(), reason="interpolate doesn't work for string"
70-
)
71-
def test_interp_basic(self):
67+
def test_interp_basic(self, using_infer_string):
7268
df = DataFrame(
7369
{
7470
"A": [1, 2, np.nan, 4],
@@ -77,7 +73,8 @@ def test_interp_basic(self):
7773
"D": list("abcd"),
7874
}
7975
)
80-
msg = "DataFrame cannot interpolate with object dtype"
76+
dtype = "str" if using_infer_string else "object"
77+
msg = f"[Cc]annot interpolate with {dtype} dtype"
8178
with pytest.raises(TypeError, match=msg):
8279
df.interpolate()
8380

@@ -88,7 +85,8 @@ def test_interp_basic(self):
8885

8986
# check we DID operate inplace
9087
assert np.shares_memory(df["C"]._values, cvalues)
91-
assert np.shares_memory(df["D"]._values, dvalues)
88+
if not using_infer_string:
89+
assert np.shares_memory(df["D"]._values, dvalues)
9290

9391
@pytest.mark.xfail(
9492
using_string_dtype(), reason="interpolate doesn't work for string"

0 commit comments

Comments
 (0)