From 4ba25b631573a8d43f56a5385b00d161e62e6568 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Sun, 11 Jan 2026 15:12:51 +0100 Subject: [PATCH 1/2] ENH: add a basic test of isin --- array_api_tests/_array_module.py | 2 ++ array_api_tests/test_set_functions.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/array_api_tests/_array_module.py b/array_api_tests/_array_module.py index 1c52a983..96d0d452 100644 --- a/array_api_tests/_array_module.py +++ b/array_api_tests/_array_module.py @@ -35,6 +35,8 @@ def __repr__(self): _funcs += ["take", "isdtype", "conj", "imag", "real"] # TODO: bump spec and update array-api-tests to new spec layout _top_level_attrs = _dtypes + _constants + _funcs + stubs.EXTENSIONS + ["fft"] +_top_level_attrs += ['isin'] # FIXME: until the spec is not updated + for attr in _top_level_attrs: try: globals()[attr] = getattr(xp, attr) diff --git a/array_api_tests/test_set_functions.py b/array_api_tests/test_set_functions.py index 8a6f7a9d..d72fb1e5 100644 --- a/array_api_tests/test_set_functions.py +++ b/array_api_tests/test_set_functions.py @@ -5,6 +5,7 @@ import pytest from hypothesis import assume, given +from hypothesis import strategies as st from . import _array_module as xp from . import dtype_helpers as dh @@ -256,3 +257,23 @@ def test_unique_values(x): except Exception as exc: ph.add_note(exc, repro_snippet) raise + + +@given( + *hh.two_mutual_arrays(two_shapes=st.tuples(hh.shapes(), hh.shapes())), + hh.kwargs(invert=st.booleans()) +) +def test_isin(x1, x2, kw): + print("\nx1 = ", type(x1)) + print(x1.shape, x2.shape, x1.dtype, x2.dtype, kw) + + repro_snippet = ph.format_snippet(f"xp.isin({x1!r}, {x2!r}, **kw) with {kw = }") + try: + out = xp.isin(x1, x2, **kw) + + assert out.dtype == xp.bool + assert out.shape == x1.shape + # TODO value tests + except Exception as exc: + ph.add_note(exc, repro_snippet) + raise From 3db170a63a88a5eefea39f4fab4bb804416c9015 Mon Sep 17 00:00:00 2001 From: Evgeni Burovski Date: Sun, 11 Jan 2026 15:53:30 +0100 Subject: [PATCH 2/2] ENH: add test for isin with scalars --- array_api_tests/test_set_functions.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/array_api_tests/test_set_functions.py b/array_api_tests/test_set_functions.py index d72fb1e5..b349c500 100644 --- a/array_api_tests/test_set_functions.py +++ b/array_api_tests/test_set_functions.py @@ -277,3 +277,22 @@ def test_isin(x1, x2, kw): except Exception as exc: ph.add_note(exc, repro_snippet) raise + + +@given( + x1x2=hh.array_and_py_scalar(dh.all_dtypes), + kw=hh.kwargs(invert=st.booleans()) +) +def test_isin_scalars(x1x2, kw): + x1, x2 = x1x2 + + repro_snippet = ph.format_snippet(f"xp.isin({x1!r}, {x2!r}, **kw) with {kw = }") + try: + out = xp.isin(x1, x2, **kw) + + assert out.dtype == xp.bool + assert out.shape == () if isinstance(x1, bool | int | float | complex) else x1.shape + # TODO value tests + except Exception as exc: + ph.add_note(exc, repro_snippet) + raise