Skip to content

Adjust tests for apply folder for new string option #56190

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
merged 3 commits into from
Nov 30, 2023
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
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 @@ -224,9 +224,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 @@ -249,11 +254,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