Skip to content

Commit 2fcf538

Browse files
authored
Merge pull request #426 from ev-br/test_isin2
ENH: add a basic test of isin
2 parents 844bd77 + 7642434 commit 2fcf538

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

array_api_tests/test_set_functions.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77
from hypothesis import assume, given
8+
from hypothesis import strategies as st
89

910
from . import _array_module as xp
1011
from . import dtype_helpers as dh
@@ -256,3 +257,44 @@ def test_unique_values(x):
256257
except Exception as exc:
257258
ph.add_note(exc, repro_snippet)
258259
raise
260+
261+
262+
@pytest.mark.min_version("2025.12")
263+
class TestIsin:
264+
@given(
265+
hh.mutually_promotable_dtypes(2, dtypes=dh.all_int_dtypes),
266+
hh.kwargs(invert=st.booleans()),
267+
st.data()
268+
)
269+
def test_isin(self, dt, kw, data):
270+
x1 = data.draw(hh.arrays(dtype=dt[0], shape=hh.shapes()))
271+
x2 = data.draw(hh.arrays(dtype=dt[1], shape=hh.shapes()))
272+
273+
repro_snippet = ph.format_snippet(f"xp.isin({x1!r}, {x2!r}, **kw) with {kw = }")
274+
try:
275+
out = xp.isin(x1, x2, **kw)
276+
277+
assert out.dtype == xp.bool
278+
assert out.shape == x1.shape
279+
# TODO value tests
280+
except Exception as exc:
281+
ph.add_note(exc, repro_snippet)
282+
raise
283+
284+
@given(
285+
x1x2=hh.array_and_py_scalar(dh.all_int_dtypes),
286+
kw=hh.kwargs(invert=st.booleans())
287+
)
288+
def test_isin_scalars(self, x1x2, kw):
289+
x1, x2 = x1x2
290+
291+
repro_snippet = ph.format_snippet(f"xp.isin({x1!r}, {x2!r}, **kw) with {kw = }")
292+
try:
293+
out = xp.isin(x1, x2, **kw)
294+
295+
assert out.dtype == xp.bool
296+
assert out.shape == () if isinstance(x1, int) else x1.shape
297+
# TODO value tests
298+
except Exception as exc:
299+
ph.add_note(exc, repro_snippet)
300+
raise

0 commit comments

Comments
 (0)