From 2d622814d045ac48e1842deec85309fcc9cc6f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20L=C3=B6ffler?= Date: Fri, 22 Sep 2023 18:00:23 +0300 Subject: [PATCH] skip instead of xfail missing implementations --- numpy_groupies/tests/__init__.py | 17 +++++++++-------- numpy_groupies/tests/test_compare.py | 10 +++++----- numpy_groupies/tests/test_generic.py | 14 +++++++------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/numpy_groupies/tests/__init__.py b/numpy_groupies/tests/__init__.py index f0dcddd..4effe50 100644 --- a/numpy_groupies/tests/__init__.py +++ b/numpy_groupies/tests/__init__.py @@ -1,3 +1,5 @@ +from functools import wraps + import pytest from .. import aggregate_numpy, aggregate_numpy_ufunc, aggregate_purepy @@ -36,10 +38,11 @@ def _impl_name(impl): } -def _wrap_notimplemented_xfail(impl, name=None): - """Some implementations lack some functionality. That's ok, let's xfail that instead of raising errors.""" +def _wrap_notimplemented_skip(impl, name=None): + """Some implementations lack some functionality. That's ok, let's skip that instead of raising errors.""" - def try_xfail(*args, **kwargs): + @wraps(impl) + def try_skip(*args, **kwargs): try: return impl(*args, **kwargs) except NotImplementedError as e: @@ -49,15 +52,13 @@ def try_xfail(*args, **kwargs): func = func.__name__ not_implemented_ok = _not_implemented_by_impl_name.get(impl_name, []) if not_implemented_ok == "NO_CHECK" or func in not_implemented_ok: - pytest.xfail("Functionality not implemented") + pytest.skip("Functionality not implemented") else: raise e if name: - try_xfail.__name__ = name - else: - try_xfail.__name__ = impl.__name__ - return try_xfail + try_skip.__name__ = name + return try_skip func_list = ( diff --git a/numpy_groupies/tests/test_compare.py b/numpy_groupies/tests/test_compare.py index e4158fc..4261541 100644 --- a/numpy_groupies/tests/test_compare.py +++ b/numpy_groupies/tests/test_compare.py @@ -12,7 +12,7 @@ from . import ( _impl_name, - _wrap_notimplemented_xfail, + _wrap_notimplemented_skip, aggregate_numba, aggregate_numpy, aggregate_numpy_ufunc, @@ -34,7 +34,7 @@ def aggregate_cmp(request, seed=100): test_pair = request.param if test_pair == "np/py": # Some functions in purepy are not implemented - func_ref = _wrap_notimplemented_xfail(aggregate_purepy.aggregate) + func_ref = _wrap_notimplemented_skip(aggregate_purepy.aggregate) func = aggregate_numpy.aggregate group_cnt = 100 else: @@ -52,7 +52,7 @@ def aggregate_cmp(request, seed=100): if not impl: pytest.skip("Implementation not available") name = _impl_name(impl) - func = _wrap_notimplemented_xfail(impl.aggregate, "aggregate_" + name) + func = _wrap_notimplemented_skip(impl.aggregate, "aggregate_" + name) rnd = np.random.RandomState(seed=seed) @@ -114,7 +114,7 @@ def test_cmp(aggregate_cmp, func, fill_value, decimal=10): res = aggregate_cmp.func(aggregate_cmp.group_idx, a, func=func, fill_value=fill_value) except ValueError: if np.isnan(fill_value) and aggregate_cmp.test_pair.endswith("py"): - pytest.xfail( + pytest.skip( "pure python version uses lists and does not raise ValueErrors when inserting nan into integers" ) else: @@ -125,7 +125,7 @@ def test_cmp(aggregate_cmp, func, fill_value, decimal=10): np.testing.assert_allclose(res, ref, rtol=10**-decimal) except AssertionError: if "arg" in func and aggregate_cmp.test_pair.startswith("pandas"): - pytest.xfail("pandas doesn't fill indices for all-nan groups with fill_value, but with -inf instead") + pytest.skip("pandas doesn't fill indices for all-nan groups with fill_value, but with -inf instead") else: raise diff --git a/numpy_groupies/tests/test_generic.py b/numpy_groupies/tests/test_generic.py index 0519161..9cf99fa 100644 --- a/numpy_groupies/tests/test_generic.py +++ b/numpy_groupies/tests/test_generic.py @@ -6,7 +6,7 @@ import numpy as np import pytest -from . import _impl_name, _implementations, _wrap_notimplemented_xfail, func_list +from . import _impl_name, _implementations, _wrap_notimplemented_skip, func_list @pytest.fixture(params=_implementations, ids=_impl_name) @@ -15,7 +15,7 @@ def aggregate_all(request): if impl is None: pytest.skip("Implementation not available") name = _impl_name(impl) - return _wrap_notimplemented_xfail(impl.aggregate, "aggregate_" + name) + return _wrap_notimplemented_skip(impl.aggregate, "aggregate_" + name) def _deselect_purepy(aggregate_all, *args, **kwargs): @@ -229,7 +229,7 @@ def test_scalar_input(aggregate_all, func): @pytest.mark.parametrize("func", ["sum", "prod", "mean", "var", "std", "all", "any"]) def test_nan_input(aggregate_all, func, groups=100): if aggregate_all.__name__.endswith("pandas"): - pytest.xfail("pandas always skips nan values") + pytest.skip("pandas always skips nan values") group_idx = np.arange(0, groups, dtype=int).repeat(5) a = np.random.random(group_idx.size) a[::2] = np.nan @@ -244,7 +244,7 @@ def test_nan_input(aggregate_all, func, groups=100): def test_nan_input_len(aggregate_all, groups=100, group_size=5): if aggregate_all.__name__.endswith("pandas"): - pytest.xfail("pandas always skips nan values") + pytest.skip("pandas always skips nan values") group_idx = np.arange(0, groups, dtype=int).repeat(group_size) a = np.random.random(len(group_idx)) a[::2] = np.nan @@ -267,7 +267,7 @@ def test_argmin_argmax_nonans(aggregate_all): @pytest.mark.deselect_if(func=_deselect_purepy) def test_argmin_argmax_nans(aggregate_all): if aggregate_all.__name__.endswith("pandas"): - pytest.xfail("pandas always ignores nans") + pytest.skip("pandas always ignores nans") group_idx = np.array([0, 0, 0, 0, 3, 3, 3, 3]) a = np.array([4, 4, 3, 1, np.nan, 1, 2, 3]) @@ -282,7 +282,7 @@ def test_argmin_argmax_nans(aggregate_all): @pytest.mark.deselect_if(func=_deselect_purepy) def test_nanargmin_nanargmax_nans(aggregate_all): if aggregate_all.__name__.endswith("pandas"): - pytest.xfail("pandas doesn't fill indices for all-nan groups with fill_value but with -inf instead") + pytest.skip("pandas doesn't fill indices for all-nan groups with fill_value but with -inf instead") group_idx = np.array([0, 0, 0, 0, 3, 3, 3, 3]) a = np.array([4, 4, np.nan, 1, np.nan, np.nan, np.nan, np.nan]) @@ -491,7 +491,7 @@ def test_argreduction_nD_array_1D_idx(aggregate_all): @pytest.mark.deselect_if(func=_deselect_purepy) def test_argreduction_negative_fill_value(aggregate_all): if aggregate_all.__name__.endswith("pandas"): - pytest.xfail("pandas always skips nan values") + pytest.skip("pandas always skips nan values") group_idx = np.array([0, 0, 2, 2, 2, 1, 1, 2, 2, 1, 1, 0], dtype=int) a = np.array([[1] * 12, [np.nan] * 12])