Skip to content

Commit 75a4423

Browse files
authored
TST: tighten xfails in test_strings (#33932)
1 parent 07402f6 commit 75a4423

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

pandas/tests/test_strings.py

+19-31
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,8 @@ def test_api_per_dtype(self, index_or_series, dtype, any_skipna_inferred_dtype):
209209
box = index_or_series
210210
inferred_dtype, values = any_skipna_inferred_dtype
211211

212-
if dtype == "category" and len(values) and values[1] is pd.NA:
213-
pytest.xfail(reason="Categorical does not yet support pd.NA")
214-
215212
t = box(values, dtype=dtype) # explicit dtype to avoid casting
216213

217-
# TODO: get rid of these xfails
218-
if dtype == "category" and inferred_dtype in ["period", "interval"]:
219-
pytest.xfail(
220-
reason="Conversion to numpy array fails because "
221-
"the ._values-attribute is not a numpy array for "
222-
"PeriodArray/IntervalArray; see GH 23553"
223-
)
224-
225214
types_passing_constructor = [
226215
"string",
227216
"unicode",
@@ -247,6 +236,7 @@ def test_api_per_method(
247236
dtype,
248237
any_allowed_skipna_inferred_dtype,
249238
any_string_method,
239+
request,
250240
):
251241
# this test does not check correctness of the different methods,
252242
# just that the methods work on the specified (inferred) dtypes,
@@ -258,26 +248,24 @@ def test_api_per_method(
258248
method_name, args, kwargs = any_string_method
259249

260250
# TODO: get rid of these xfails
261-
if (
262-
method_name in ["partition", "rpartition"]
263-
and box == Index
264-
and inferred_dtype == "empty"
265-
):
266-
pytest.xfail(reason="Method cannot deal with empty Index")
267-
if (
268-
method_name == "split"
269-
and box == Index
270-
and values.size == 0
271-
and kwargs.get("expand", None) is not None
272-
):
273-
pytest.xfail(reason="Split fails on empty Series when expand=True")
274-
if (
275-
method_name == "get_dummies"
276-
and box == Index
277-
and inferred_dtype == "empty"
278-
and (dtype == object or values.size == 0)
279-
):
280-
pytest.xfail(reason="Need to fortify get_dummies corner cases")
251+
reason = None
252+
if box is Index and values.size == 0:
253+
if method_name in ["partition", "rpartition"] and kwargs.get(
254+
"expand", True
255+
):
256+
reason = "Method cannot deal with empty Index"
257+
elif method_name == "split" and kwargs.get("expand", None):
258+
reason = "Split fails on empty Series when expand=True"
259+
elif method_name == "get_dummies":
260+
reason = "Need to fortify get_dummies corner cases"
261+
262+
elif box is Index and inferred_dtype == "empty" and dtype == object:
263+
if method_name == "get_dummies":
264+
reason = "Need to fortify get_dummies corner cases"
265+
266+
if reason is not None:
267+
mark = pytest.mark.xfail(reason=reason)
268+
request.node.add_marker(mark)
281269

282270
t = box(values, dtype=dtype) # explicit dtype to avoid casting
283271
method = getattr(t.str, method_name)

0 commit comments

Comments
 (0)