Skip to content

Commit c608062

Browse files
authored
Merge pull request #105 from crusaderky/test-labels
2 parents 39f6a27 + 20cb3b9 commit c608062

File tree

7 files changed

+48
-28
lines changed

7 files changed

+48
-28
lines changed

src/array_api_extra/_delegation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def pad(
7777
pad_width = xp.flip(pad_width, axis=(0,)).flatten()
7878
return xp.nn.functional.pad(x, tuple(pad_width), value=constant_values) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
7979

80-
if _delegate(xp, Backend.NUMPY, Backend.JAX_NUMPY, Backend.CUPY):
80+
if _delegate(xp, Backend.NUMPY, Backend.JAX, Backend.CUPY):
8181
return xp.pad(x, pad_width, mode, constant_values=constant_values)
8282

8383
return _funcs.pad(x, pad_width, constant_values=constant_values, xp=xp)

src/array_api_extra/_lib/_backends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class Backend(Enum): # numpydoc ignore=PR01,PR02 # type: ignore[no-subclass-an
2828
NUMPY_READONLY = "numpy_readonly", _compat.is_numpy_namespace
2929
CUPY = "cupy", _compat.is_cupy_namespace
3030
TORCH = "torch", _compat.is_torch_namespace
31-
DASK_ARRAY = "dask.array", _compat.is_dask_namespace
31+
DASK = "dask.array", _compat.is_dask_namespace
3232
SPARSE = "sparse", _compat.is_pydata_sparse_namespace
33-
JAX_NUMPY = "jax.numpy", _compat.is_jax_namespace
33+
JAX = "jax.numpy", _compat.is_jax_namespace
3434

3535
def __new__(
3636
cls, value: str, _is_namespace: Callable[[ModuleType], bool]

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def xp(library: Backend) -> ModuleType: # numpydoc ignore=PR01,RT03
104104
if library == Backend.NUMPY_READONLY:
105105
return NumPyReadOnly() # type: ignore[return-value] # pyright: ignore[reportReturnType]
106106
xp = pytest.importorskip(library.value)
107-
if library == Backend.JAX_NUMPY:
107+
if library == Backend.JAX:
108108
import jax
109109

110110
# suppress unused-ignore to run mypy in -e lint as well as -e dev

tests/test_at.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def assert_copy(array: Array, copy: bool | None) -> Generator[None, None, None]:
3131

3232

3333
@pytest.mark.skip_xp_backend(
34-
Backend.SPARSE, reason="read-only backend without .at support"
34+
Backend.SPARSE, reason="sparse:read-only backend without .at support"
3535
)
3636
@pytest.mark.parametrize(
3737
("kwargs", "expect_copy"),

tests/test_funcs.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# mypy: disable-error-code=no-untyped-usage
2727

2828

29-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no expand_dims")
29+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims")
3030
class TestAtLeastND:
3131
def test_0D(self, xp: ModuleType):
3232
x = xp.asarray(1.0)
@@ -98,7 +98,7 @@ def test_xp(self, xp: ModuleType):
9898
xp_assert_equal(y, x)
9999

100100

101-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype")
101+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype")
102102
class TestCov:
103103
def test_basic(self, xp: ModuleType):
104104
xp_assert_close(
@@ -137,15 +137,17 @@ def test_device(self, xp: ModuleType, device: Device):
137137
x = xp.asarray([1, 2, 3], device=device)
138138
assert get_device(cov(x)) == device
139139

140-
@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY)
140+
@pytest.mark.skip_xp_backend(
141+
Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp"
142+
)
141143
def test_xp(self, xp: ModuleType):
142144
xp_assert_close(
143145
cov(xp.asarray([[0.0, 2.0], [1.0, 1.0], [2.0, 0.0]]).T, xp=xp),
144146
xp.asarray([[1.0, -1.0], [-1.0, 1.0]], dtype=xp.float64),
145147
)
146148

147149

148-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device")
150+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no device kwarg in asarray")
149151
class TestCreateDiagonal:
150152
def test_1d(self, xp: ModuleType):
151153
# from np.diag tests
@@ -191,10 +193,10 @@ def test_xp(self, xp: ModuleType):
191193
xp_assert_equal(y, xp.asarray([[1, 0], [0, 2]]))
192194

193195

194-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no sparse.expand_dims")
196+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims")
195197
class TestExpandDims:
196-
@pytest.mark.skip_xp_backend(Backend.DASK_ARRAY, reason="tuple index out of range")
197-
@pytest.mark.skip_xp_backend(Backend.TORCH, reason="tuple index out of range")
198+
@pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:tuple index out of range")
199+
@pytest.mark.skip_xp_backend(Backend.TORCH, reason="torch:tuple index out of range")
198200
def test_functionality(self, xp: ModuleType):
199201
def _squeeze_all(b: Array) -> Array:
200202
"""Mimics `np.squeeze(b)`. `xpx.squeeze`?"""
@@ -252,7 +254,7 @@ def test_xp(self, xp: ModuleType):
252254
assert y.shape == (1, 1, 1, 3)
253255

254256

255-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no sparse.expand_dims")
257+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no expand_dims")
256258
class TestKron:
257259
def test_basic(self, xp: ModuleType):
258260
# Using 0-dimensional array
@@ -349,7 +351,9 @@ def test_xp(self, xp: ModuleType):
349351
xp_assert_equal(nunique(a, xp=xp), xp.asarray(3))
350352

351353

352-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no arange, no device")
354+
@pytest.mark.skip_xp_backend(
355+
Backend.SPARSE, reason="sparse:no arange, no device kwarg in asarray"
356+
)
353357
class TestPad:
354358
def test_simple(self, xp: ModuleType):
355359
a = xp.arange(1, 4)
@@ -399,8 +403,8 @@ def test_list_of_tuples_width(self, xp: ModuleType):
399403
assert padded.shape == (4, 4)
400404

401405

402-
@pytest.mark.skip_xp_backend(Backend.DASK_ARRAY, reason="no argsort")
403-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device")
406+
@pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:no argsort")
407+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no device kwarg in asarray")
404408
class TestSetDiff1D:
405409
@pytest.mark.skip_xp_backend(
406410
Backend.TORCH, reason="index_select not implemented for uint32"
@@ -436,7 +440,9 @@ def test_device(self, xp: ModuleType, device: Device):
436440
x2 = xp.asarray([2, 3, 4], device=device)
437441
assert get_device(setdiff1d(x1, x2)) == device
438442

439-
@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY)
443+
@pytest.mark.skip_xp_backend(
444+
Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp"
445+
)
440446
def test_xp(self, xp: ModuleType):
441447
x1 = xp.asarray([3, 8, 20])
442448
x2 = xp.asarray([2, 3, 4])
@@ -445,7 +451,7 @@ def test_xp(self, xp: ModuleType):
445451
xp_assert_equal(actual, expected)
446452

447453

448-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype")
454+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype")
449455
class TestSinc:
450456
def test_simple(self, xp: ModuleType):
451457
xp_assert_equal(sinc(xp.asarray(0.0)), xp.asarray(1.0))

tests/test_testing.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
xp_assert_equal,
1818
pytest.param(
1919
xp_assert_close,
20-
marks=pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype"),
20+
marks=pytest.mark.skip_xp_backend(
21+
Backend.SPARSE, reason="sparse:no isdtype"
22+
),
2123
),
2224
],
2325
)
@@ -38,15 +40,19 @@ def test_assert_close_equal_basic(xp: ModuleType, func: Callable[..., None]): #
3840
func(xp.asarray([1, 2]), xp.asarray([1, 3]), err_msg="hello")
3941

4042

41-
@pytest.mark.skip_xp_backend(Backend.NUMPY)
42-
@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY)
43+
@pytest.mark.skip_xp_backend(Backend.NUMPY, reason="numpy:test other ns vs. numpy")
44+
@pytest.mark.skip_xp_backend(
45+
Backend.NUMPY_READONLY, reason="numpy_readonly:test other ns vs. numpy"
46+
)
4347
@pytest.mark.parametrize(
4448
"func",
4549
[
4650
xp_assert_equal,
4751
pytest.param(
4852
xp_assert_close,
49-
marks=pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype"),
53+
marks=pytest.mark.skip_xp_backend(
54+
Backend.SPARSE, reason="sparse:no isdtype"
55+
),
5056
),
5157
],
5258
)
@@ -59,7 +65,7 @@ def test_assert_close_equal_namespace(xp: ModuleType, func: Callable[..., None])
5965
func(xp.asarray([0]), [0])
6066

6167

62-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no isdtype")
68+
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="sparse:no isdtype")
6369
def test_assert_close_tolerance(xp: ModuleType):
6470
xp_assert_close(xp.asarray([100.0]), xp.asarray([102.0]), rtol=0.03)
6571
with pytest.raises(AssertionError):

tests/test_utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313

1414
class TestIn1D:
15-
@pytest.mark.skip_xp_backend(Backend.DASK_ARRAY, reason="no argsort")
16-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no unique_inverse, no device")
15+
@pytest.mark.skip_xp_backend(Backend.DASK, reason="dask:no argsort")
16+
@pytest.mark.skip_xp_backend(
17+
Backend.SPARSE, reason="sparse:no unique_inverse, no device kwarg in asarray"
18+
)
1719
# cover both code paths
1820
@pytest.mark.parametrize("n", [9, 15])
1921
def test_no_invert_assume_unique(self, xp: ModuleType, n: int):
@@ -23,14 +25,20 @@ def test_no_invert_assume_unique(self, xp: ModuleType, n: int):
2325
actual = in1d(x1, x2)
2426
xp_assert_equal(actual, expected)
2527

26-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no device")
28+
@pytest.mark.skip_xp_backend(
29+
Backend.SPARSE, reason="sparse: no device kwarg in asarray"
30+
)
2731
def test_device(self, xp: ModuleType, device: Device):
2832
x1 = xp.asarray([3, 8, 20], device=device)
2933
x2 = xp.asarray([2, 3, 4], device=device)
3034
assert get_device(in1d(x1, x2)) == device
3135

32-
@pytest.mark.skip_xp_backend(Backend.NUMPY_READONLY)
33-
@pytest.mark.skip_xp_backend(Backend.SPARSE, reason="no arange, no device")
36+
@pytest.mark.skip_xp_backend(
37+
Backend.NUMPY_READONLY, reason="numpy_readonly:explicit xp"
38+
)
39+
@pytest.mark.skip_xp_backend(
40+
Backend.SPARSE, reason="sparse:no arange, no device kwarg in asarray"
41+
)
3442
def test_xp(self, xp: ModuleType):
3543
x1 = xp.asarray([1, 6])
3644
x2 = xp.arange(5)

0 commit comments

Comments
 (0)