|
10 | 10 | from pandas.core import strings as strings
|
11 | 11 |
|
12 | 12 |
|
13 |
| -def test_api(): |
| 13 | +def test_api(any_string_dtype): |
14 | 14 |
|
15 | 15 | # GH 6106, GH 9322
|
16 | 16 | assert Series.str is strings.StringMethods
|
17 |
| - assert isinstance(Series([""]).str, strings.StringMethods) |
| 17 | + assert isinstance(Series([""], dtype=any_string_dtype).str, strings.StringMethods) |
18 | 18 |
|
19 | 19 |
|
20 | 20 | def test_api_mi_raises():
|
@@ -74,18 +74,26 @@ def test_api_per_method(
|
74 | 74 | reason = None
|
75 | 75 | if box is Index and values.size == 0:
|
76 | 76 | if method_name in ["partition", "rpartition"] and kwargs.get("expand", True):
|
| 77 | + raises = TypeError |
77 | 78 | reason = "Method cannot deal with empty Index"
|
78 | 79 | elif method_name == "split" and kwargs.get("expand", None):
|
| 80 | + raises = TypeError |
79 | 81 | reason = "Split fails on empty Series when expand=True"
|
80 | 82 | elif method_name == "get_dummies":
|
| 83 | + raises = ValueError |
81 | 84 | reason = "Need to fortify get_dummies corner cases"
|
82 | 85 |
|
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" |
86 | 94 |
|
87 | 95 | if reason is not None:
|
88 |
| - mark = pytest.mark.xfail(reason=reason) |
| 96 | + mark = pytest.mark.xfail(raises=raises, reason=reason) |
89 | 97 | request.node.add_marker(mark)
|
90 | 98 |
|
91 | 99 | t = box(values, dtype=dtype) # explicit dtype to avoid casting
|
@@ -117,17 +125,23 @@ def test_api_per_method(
|
117 | 125 | method(*args, **kwargs)
|
118 | 126 |
|
119 | 127 |
|
120 |
| -def test_api_for_categorical(any_string_method): |
| 128 | +def test_api_for_categorical(any_string_method, any_string_dtype, request): |
121 | 129 | # 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) |
123 | 137 | s = s + " " + s
|
124 | 138 | c = s.astype("category")
|
125 | 139 | assert isinstance(c.str, strings.StringMethods)
|
126 | 140 |
|
127 | 141 | method_name, args, kwargs = any_string_method
|
128 | 142 |
|
129 | 143 | 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) |
131 | 145 |
|
132 | 146 | if isinstance(result, DataFrame):
|
133 | 147 | tm.assert_frame_equal(result, expected)
|
|
0 commit comments