Skip to content

Commit 7612d9d

Browse files
committed
ENH: add a basic test of isin
1 parent 1707f38 commit 7612d9d

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

array_api_tests/test_set_functions.py

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

0 commit comments

Comments
 (0)