From 78a21f4f088a4bf036a016feff5b623fc0c698f2 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler <61934744+phofl@users.noreply.github.com> Date: Sun, 26 Nov 2023 21:32:09 +0100 Subject: [PATCH] Adjust tests for apply folder for new string option --- pandas/tests/apply/test_frame_apply.py | 9 ++++++--- pandas/tests/apply/test_invalid_arg.py | 18 +++++++++++++++--- pandas/tests/apply/test_series_apply.py | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pandas/tests/apply/test_frame_apply.py b/pandas/tests/apply/test_frame_apply.py index 2d7549e09a986..b7eac6b8f0ea1 100644 --- a/pandas/tests/apply/test_frame_apply.py +++ b/pandas/tests/apply/test_frame_apply.py @@ -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)() diff --git a/pandas/tests/apply/test_invalid_arg.py b/pandas/tests/apply/test_invalid_arg.py index 9f8611dd4b08b..ad269b745004b 100644 --- a/pandas/tests/apply/test_invalid_arg.py +++ b/pandas/tests/apply/test_invalid_arg.py @@ -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"): @@ -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): diff --git a/pandas/tests/apply/test_series_apply.py b/pandas/tests/apply/test_series_apply.py index 177dff2d771d4..24e48ebd4ed54 100644 --- a/pandas/tests/apply/test_series_apply.py +++ b/pandas/tests/apply/test_series_apply.py @@ -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")) @@ -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]])