Skip to content

Commit 6f5fb81

Browse files
committed
TST: Test size()
1 parent beac55b commit 6f5fb81

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

tests/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
all_libraries.append('sparse')
1212

1313
def import_(library, wrapper=False):
14-
if library == 'cupy':
14+
if library in ('cupy', 'ndonnx'):
1515
pytest.importorskip(library)
1616
if wrapper:
1717
if 'jax' in library:

tests/test_common.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
is_dask_namespace, is_jax_namespace, is_pydata_sparse_namespace,
66
)
77

8-
from array_api_compat import device, is_array_api_obj, is_writeable_array, to_device
9-
8+
from array_api_compat import (
9+
device, is_array_api_obj, is_writeable_array, size, to_device
10+
)
1011
from ._helpers import import_, wrapped_libraries, all_libraries
1112

1213
import pytest
@@ -92,6 +93,27 @@ def test_is_writeable_array_numpy():
9293
assert not is_writeable_array(x)
9394

9495

96+
@pytest.mark.parametrize("library", all_libraries)
97+
def test_size(library):
98+
xp = import_(library)
99+
x = xp.asarray([1, 2, 3])
100+
assert size(x) == 3
101+
102+
103+
def test_size_nan():
104+
xp = import_("dask.array")
105+
x = xp.arange(10)
106+
x = x[x < 5]
107+
assert np.isnan(size(x))
108+
109+
110+
def test_size_none():
111+
xp = import_("ndonnx")
112+
x = xp.arange(10)
113+
x = x[x < 5]
114+
assert size(x) is None
115+
116+
95117
@pytest.mark.parametrize("library", all_libraries)
96118
def test_device(library):
97119
xp = import_(library, wrapper=True)

0 commit comments

Comments
 (0)