Skip to content

Commit 0c7b728

Browse files
[ArrowStringArray] TST: parametrize (part) pandas/tests/strings/test_api.py (#41470)
1 parent e865ec7 commit 0c7b728

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

pandas/tests/strings/test_api.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
from pandas.core import strings as strings
1111

1212

13-
def test_api():
13+
def test_api(any_string_dtype):
1414

1515
# GH 6106, GH 9322
1616
assert Series.str is strings.StringMethods
17-
assert isinstance(Series([""]).str, strings.StringMethods)
17+
assert isinstance(Series([""], dtype=any_string_dtype).str, strings.StringMethods)
1818

1919

2020
def test_api_mi_raises():
@@ -74,18 +74,26 @@ def test_api_per_method(
7474
reason = None
7575
if box is Index and values.size == 0:
7676
if method_name in ["partition", "rpartition"] and kwargs.get("expand", True):
77+
raises = TypeError
7778
reason = "Method cannot deal with empty Index"
7879
elif method_name == "split" and kwargs.get("expand", None):
80+
raises = TypeError
7981
reason = "Split fails on empty Series when expand=True"
8082
elif method_name == "get_dummies":
83+
raises = ValueError
8184
reason = "Need to fortify get_dummies corner cases"
8285

83-
elif box is Index and inferred_dtype == "empty" and dtype == object:
84-
if method_name == "get_dummies":
85-
reason = "Need to fortify get_dummies corner cases"
86+
elif (
87+
box is Index
88+
and inferred_dtype == "empty"
89+
and dtype == object
90+
and method_name == "get_dummies"
91+
):
92+
raises = ValueError
93+
reason = "Need to fortify get_dummies corner cases"
8694

8795
if reason is not None:
88-
mark = pytest.mark.xfail(reason=reason)
96+
mark = pytest.mark.xfail(raises=raises, reason=reason)
8997
request.node.add_marker(mark)
9098

9199
t = box(values, dtype=dtype) # explicit dtype to avoid casting
@@ -117,17 +125,23 @@ def test_api_per_method(
117125
method(*args, **kwargs)
118126

119127

120-
def test_api_for_categorical(any_string_method):
128+
def test_api_for_categorical(any_string_method, any_string_dtype, request):
121129
# https://github.com/pandas-dev/pandas/issues/10661
122-
s = Series(list("aabb"))
130+
131+
if any_string_dtype == "arrow_string":
132+
# unsupported operand type(s) for +: 'ArrowStringArray' and 'str'
133+
mark = pytest.mark.xfail(raises=TypeError, reason="Not Implemented")
134+
request.node.add_marker(mark)
135+
136+
s = Series(list("aabb"), dtype=any_string_dtype)
123137
s = s + " " + s
124138
c = s.astype("category")
125139
assert isinstance(c.str, strings.StringMethods)
126140

127141
method_name, args, kwargs = any_string_method
128142

129143
result = getattr(c.str, method_name)(*args, **kwargs)
130-
expected = getattr(s.str, method_name)(*args, **kwargs)
144+
expected = getattr(s.astype("object").str, method_name)(*args, **kwargs)
131145

132146
if isinstance(result, DataFrame):
133147
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)