Skip to content

Commit eb7a8c8

Browse files
authored
Adjust tests for apply folder for new string option (#56190)
* BUG: numba raises for string columns or index * Adjust tests for apply folder for new string option
1 parent 9cbf95d commit eb7a8c8

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

pandas/tests/apply/test_frame_apply.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1464,13 +1464,16 @@ def test_apply_datetime_tz_issue(engine, request):
14641464

14651465
@pytest.mark.parametrize("df", [DataFrame({"A": ["a", None], "B": ["c", "d"]})])
14661466
@pytest.mark.parametrize("method", ["min", "max", "sum"])
1467-
def test_mixed_column_raises(df, method):
1467+
def test_mixed_column_raises(df, method, using_infer_string):
14681468
# GH 16832
14691469
if method == "sum":
1470-
msg = r'can only concatenate str \(not "int"\) to str'
1470+
msg = r'can only concatenate str \(not "int"\) to str|does not support'
14711471
else:
14721472
msg = "not supported between instances of 'str' and 'float'"
1473-
with pytest.raises(TypeError, match=msg):
1473+
if not using_infer_string:
1474+
with pytest.raises(TypeError, match=msg):
1475+
getattr(df, method)()
1476+
else:
14741477
getattr(df, method)()
14751478

14761479

pandas/tests/apply/test_invalid_arg.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,14 @@ def transform2(row):
224224
DataFrame([["a", "b"], ["b", "a"]]), [["cumprod", TypeError]]
225225
),
226226
)
227-
def test_agg_cython_table_raises_frame(df, func, expected, axis):
227+
def test_agg_cython_table_raises_frame(df, func, expected, axis, using_infer_string):
228228
# GH 21224
229-
msg = "can't multiply sequence by non-int of type 'str'"
229+
if using_infer_string:
230+
import pyarrow as pa
231+
232+
expected = (expected, pa.lib.ArrowNotImplementedError)
233+
234+
msg = "can't multiply sequence by non-int of type 'str'|has no kernel"
230235
warn = None if isinstance(func, str) else FutureWarning
231236
with pytest.raises(expected, match=msg):
232237
with tm.assert_produces_warning(warn, match="using DataFrame.cumprod"):
@@ -249,11 +254,18 @@ def test_agg_cython_table_raises_frame(df, func, expected, axis):
249254
)
250255
),
251256
)
252-
def test_agg_cython_table_raises_series(series, func, expected):
257+
def test_agg_cython_table_raises_series(series, func, expected, using_infer_string):
253258
# GH21224
254259
msg = r"[Cc]ould not convert|can't multiply sequence by non-int of type"
255260
if func == "median" or func is np.nanmedian or func is np.median:
256261
msg = r"Cannot convert \['a' 'b' 'c'\] to numeric"
262+
263+
if using_infer_string:
264+
import pyarrow as pa
265+
266+
expected = (expected, pa.lib.ArrowNotImplementedError)
267+
268+
msg = msg + "|does not support|has no kernel"
257269
warn = None if isinstance(func, str) else FutureWarning
258270

259271
with pytest.raises(expected, match=msg):

pandas/tests/apply/test_series_apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def f(x):
222222
assert result == "Asia/Tokyo"
223223

224224

225-
def test_apply_categorical(by_row):
225+
def test_apply_categorical(by_row, using_infer_string):
226226
values = pd.Categorical(list("ABBABCD"), categories=list("DCBA"), ordered=True)
227227
ser = Series(values, name="XX", index=list("abcdefg"))
228228

@@ -245,7 +245,7 @@ def test_apply_categorical(by_row):
245245
result = ser.apply(lambda x: "A")
246246
exp = Series(["A"] * 7, name="XX", index=list("abcdefg"))
247247
tm.assert_series_equal(result, exp)
248-
assert result.dtype == object
248+
assert result.dtype == object if not using_infer_string else "string[pyarrow_numpy]"
249249

250250

251251
@pytest.mark.parametrize("series", [["1-1", "1-1", np.nan], ["1-1", "1-2", np.nan]])

0 commit comments

Comments
 (0)