Skip to content

Commit

Permalink
skip instead of xfail missing implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
ml31415 committed Sep 22, 2023
1 parent 985f230 commit 2d62281
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
17 changes: 9 additions & 8 deletions numpy_groupies/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from functools import wraps

import pytest

from .. import aggregate_numpy, aggregate_numpy_ufunc, aggregate_purepy
Expand Down Expand Up @@ -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:
Expand All @@ -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 = (
Expand Down
10 changes: 5 additions & 5 deletions numpy_groupies/tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from . import (
_impl_name,
_wrap_notimplemented_xfail,
_wrap_notimplemented_skip,
aggregate_numba,
aggregate_numpy,
aggregate_numpy_ufunc,
Expand All @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions numpy_groupies/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 2d62281

Please sign in to comment.