Skip to content

Commit d72e244

Browse files
authored
TST: incorrect pyarrow xfails (#50691)
* TST: incorrect pyarrow xfails * change return to pytest.skip
1 parent 0e0a447 commit d72e244

File tree

1 file changed

+80
-30
lines changed

1 file changed

+80
-30
lines changed

pandas/tests/extension/test_arrow.py

Lines changed: 80 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -354,20 +354,15 @@ def check_accumulate(self, s, op_name, skipna):
354354
self.assert_series_equal(result, expected, check_dtype=False)
355355

356356
@pytest.mark.parametrize("skipna", [True, False])
357-
def test_accumulate_series_raises(
358-
self, data, all_numeric_accumulations, skipna, request
359-
):
357+
def test_accumulate_series_raises(self, data, all_numeric_accumulations, skipna):
360358
pa_type = data.dtype.pyarrow_dtype
361359
if (
362360
(pa.types.is_integer(pa_type) or pa.types.is_floating(pa_type))
363361
and all_numeric_accumulations == "cumsum"
364362
and not pa_version_under9p0
365363
):
366-
request.node.add_marker(
367-
pytest.mark.xfail(
368-
reason=f"{all_numeric_accumulations} implemented for {pa_type}"
369-
)
370-
)
364+
pytest.skip("These work, are tested by test_accumulate_series.")
365+
371366
op_name = all_numeric_accumulations
372367
ser = pd.Series(data)
373368

@@ -377,21 +372,43 @@ def test_accumulate_series_raises(
377372
@pytest.mark.parametrize("skipna", [True, False])
378373
def test_accumulate_series(self, data, all_numeric_accumulations, skipna, request):
379374
pa_type = data.dtype.pyarrow_dtype
375+
op_name = all_numeric_accumulations
376+
ser = pd.Series(data)
377+
378+
do_skip = False
379+
if pa.types.is_string(pa_type) or pa.types.is_binary(pa_type):
380+
if op_name in ["cumsum", "cumprod"]:
381+
do_skip = True
382+
elif pa.types.is_temporal(pa_type) and not pa.types.is_duration(pa_type):
383+
if op_name in ["cumsum", "cumprod"]:
384+
do_skip = True
385+
elif pa.types.is_duration(pa_type):
386+
if op_name == "cumprod":
387+
do_skip = True
388+
389+
if do_skip:
390+
pytest.skip(
391+
"These should *not* work, we test in test_accumulate_series_raises "
392+
"that these correctly raise."
393+
)
394+
380395
if all_numeric_accumulations != "cumsum" or pa_version_under9p0:
381396
request.node.add_marker(
382397
pytest.mark.xfail(
383398
reason=f"{all_numeric_accumulations} not implemented",
384399
raises=NotImplementedError,
385400
)
386401
)
387-
elif not (pa.types.is_integer(pa_type) or pa.types.is_floating(pa_type)):
402+
elif all_numeric_accumulations == "cumsum" and (
403+
pa.types.is_duration(pa_type) or pa.types.is_boolean(pa_type)
404+
):
388405
request.node.add_marker(
389406
pytest.mark.xfail(
390-
reason=f"{all_numeric_accumulations} not implemented for {pa_type}"
407+
reason=f"{all_numeric_accumulations} not implemented for {pa_type}",
408+
raises=NotImplementedError,
391409
)
392410
)
393-
op_name = all_numeric_accumulations
394-
ser = pd.Series(data)
411+
395412
self.check_accumulate(ser, op_name, skipna)
396413

397414

@@ -418,6 +435,47 @@ def check_reduce(self, ser, op_name, skipna):
418435
@pytest.mark.parametrize("skipna", [True, False])
419436
def test_reduce_series(self, data, all_numeric_reductions, skipna, request):
420437
pa_dtype = data.dtype.pyarrow_dtype
438+
opname = all_numeric_reductions
439+
440+
ser = pd.Series(data)
441+
442+
should_work = True
443+
if pa.types.is_temporal(pa_dtype) and opname in [
444+
"sum",
445+
"var",
446+
"skew",
447+
"kurt",
448+
"prod",
449+
]:
450+
if pa.types.is_duration(pa_dtype) and opname in ["sum"]:
451+
# summing timedeltas is one case that *is* well-defined
452+
pass
453+
else:
454+
should_work = False
455+
elif (
456+
pa.types.is_string(pa_dtype) or pa.types.is_binary(pa_dtype)
457+
) and opname in [
458+
"sum",
459+
"mean",
460+
"median",
461+
"prod",
462+
"std",
463+
"sem",
464+
"var",
465+
"skew",
466+
"kurt",
467+
]:
468+
should_work = False
469+
470+
if not should_work:
471+
# matching the non-pyarrow versions, these operations *should* not
472+
# work for these dtypes
473+
msg = f"does not support reduction '{opname}'"
474+
with pytest.raises(TypeError, match=msg):
475+
getattr(ser, opname)(skipna=skipna)
476+
477+
return
478+
421479
xfail_mark = pytest.mark.xfail(
422480
raises=TypeError,
423481
reason=(
@@ -449,24 +507,16 @@ def test_reduce_series(self, data, all_numeric_reductions, skipna, request):
449507
),
450508
)
451509
)
452-
elif (
453-
not (
454-
pa.types.is_integer(pa_dtype)
455-
or pa.types.is_floating(pa_dtype)
456-
or pa.types.is_boolean(pa_dtype)
457-
)
458-
and not (
459-
all_numeric_reductions in {"min", "max"}
460-
and (
461-
(
462-
pa.types.is_temporal(pa_dtype)
463-
and not pa.types.is_duration(pa_dtype)
464-
)
465-
or pa.types.is_string(pa_dtype)
466-
or pa.types.is_binary(pa_dtype)
467-
)
468-
)
469-
and not all_numeric_reductions == "count"
510+
511+
elif all_numeric_reductions in [
512+
"mean",
513+
"median",
514+
"std",
515+
"sem",
516+
] and pa.types.is_temporal(pa_dtype):
517+
request.node.add_marker(xfail_mark)
518+
elif all_numeric_reductions in ["sum", "min", "max"] and pa.types.is_duration(
519+
pa_dtype
470520
):
471521
request.node.add_marker(xfail_mark)
472522
elif pa.types.is_boolean(pa_dtype) and all_numeric_reductions in {

0 commit comments

Comments
 (0)