Skip to content

Commit

Permalink
Adjust tests for apply folder for new string option
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl committed Nov 26, 2023
1 parent dab87c7 commit 78a21f4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
9 changes: 6 additions & 3 deletions pandas/tests/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,13 +1464,16 @@ def test_apply_datetime_tz_issue(engine, request):

@pytest.mark.parametrize("df", [DataFrame({"A": ["a", None], "B": ["c", "d"]})])
@pytest.mark.parametrize("method", ["min", "max", "sum"])
def test_mixed_column_raises(df, method):
def test_mixed_column_raises(df, method, using_infer_string):
# GH 16832
if method == "sum":
msg = r'can only concatenate str \(not "int"\) to str'
msg = r'can only concatenate str \(not "int"\) to str|does not support'
else:
msg = "not supported between instances of 'str' and 'float'"
with pytest.raises(TypeError, match=msg):
if not using_infer_string:
with pytest.raises(TypeError, match=msg):
getattr(df, method)()
else:
getattr(df, method)()


Expand Down
18 changes: 15 additions & 3 deletions pandas/tests/apply/test_invalid_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,14 @@ def transform2(row):
DataFrame([["a", "b"], ["b", "a"]]), [["cumprod", TypeError]]
),
)
def test_agg_cython_table_raises_frame(df, func, expected, axis):
def test_agg_cython_table_raises_frame(df, func, expected, axis, using_infer_string):
# GH 21224
msg = "can't multiply sequence by non-int of type 'str'"
if using_infer_string:
import pyarrow as pa

expected = (expected, pa.lib.ArrowNotImplementedError)

msg = "can't multiply sequence by non-int of type 'str'|has no kernel"
warn = None if isinstance(func, str) else FutureWarning
with pytest.raises(expected, match=msg):
with tm.assert_produces_warning(warn, match="using DataFrame.cumprod"):
Expand All @@ -248,11 +253,18 @@ def test_agg_cython_table_raises_frame(df, func, expected, axis):
)
),
)
def test_agg_cython_table_raises_series(series, func, expected):
def test_agg_cython_table_raises_series(series, func, expected, using_infer_string):
# GH21224
msg = r"[Cc]ould not convert|can't multiply sequence by non-int of type"
if func == "median" or func is np.nanmedian or func is np.median:
msg = r"Cannot convert \['a' 'b' 'c'\] to numeric"

if using_infer_string:
import pyarrow as pa

expected = (expected, pa.lib.ArrowNotImplementedError)

msg = msg + "|does not support|has no kernel"
warn = None if isinstance(func, str) else FutureWarning

with pytest.raises(expected, match=msg):
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/apply/test_series_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def f(x):
assert result == "Asia/Tokyo"


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

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


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

0 comments on commit 78a21f4

Please sign in to comment.