From 5a109fff568099e392bcb7760d774175b570bb44 Mon Sep 17 00:00:00 2001 From: hirwa Date: Mon, 8 Apr 2024 12:43:38 +0530 Subject: [PATCH 1/5] adding check for numpy version as np.bool is deprecated --- array_api_tests/dtype_helpers.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/array_api_tests/dtype_helpers.py b/array_api_tests/dtype_helpers.py index 59edfe86..6c5fa152 100644 --- a/array_api_tests/dtype_helpers.py +++ b/array_api_tests/dtype_helpers.py @@ -125,6 +125,11 @@ def _make_dtype_tuple_from_names(names: List[str]) -> Tuple[DataType]: dtypes.append(dtype) return tuple(dtypes) +# Numpy deprecated np.bool starting from version 1.20.0 +if xp.__name__ == "numpy" and xp.__version__ >="1.20.0": + array_mod_bool = xp.bool_ +else: + array_mod_bool = xp.bool uint_dtypes = _make_dtype_tuple_from_names(uint_names) int_dtypes = _make_dtype_tuple_from_names(int_names) @@ -135,15 +140,15 @@ def _make_dtype_tuple_from_names(names: List[str]) -> Tuple[DataType]: numeric_dtypes = real_dtypes if api_version > "2021.12": numeric_dtypes += complex_dtypes -all_dtypes = (xp.bool,) + numeric_dtypes +all_dtypes = (array_mod_bool,) + numeric_dtypes all_float_dtypes = real_float_dtypes if api_version > "2021.12": all_float_dtypes += complex_dtypes -bool_and_all_int_dtypes = (xp.bool,) + all_int_dtypes +bool_and_all_int_dtypes = (array_mod_bool,) + all_int_dtypes kind_to_dtypes = { - "bool": [xp.bool], + "bool": [array_mod_bool], "signed integer": int_dtypes, "unsigned integer": uint_dtypes, "integral": all_int_dtypes, @@ -400,7 +405,7 @@ def result_type(*dtypes: DataType): "the result is implementation-dependent" ) category_to_dtypes = { - "boolean": (xp.bool,), + "boolean": (array_mod_bool,), "integer": all_int_dtypes, "floating-point": real_float_dtypes, "real-valued": real_float_dtypes, @@ -554,7 +559,7 @@ def result_type(*dtypes: DataType): inplace_op_to_symbol[iop] = f"{symbol}=" func_in_dtypes[iop] = func_in_dtypes[op] func_returns_bool[iop] = func_returns_bool[op] -func_in_dtypes["__bool__"] = (xp.bool,) +func_in_dtypes["__bool__"] = (array_mod_bool,) func_in_dtypes["__int__"] = all_int_dtypes func_in_dtypes["__index__"] = all_int_dtypes func_in_dtypes["__float__"] = real_float_dtypes From 223beb9edba4e5ad8637c30cb1f1769848258c4c Mon Sep 17 00:00:00 2001 From: hirwa Date: Mon, 8 Apr 2024 13:03:49 +0530 Subject: [PATCH 2/5] Refactoring the use of xp.bool to support numpy latest version --- array_api_tests/dtype_helpers.py | 15 ++++-- array_api_tests/hypothesis_helpers.py | 7 ++- array_api_tests/test_array_object.py | 6 ++- array_api_tests/test_creation_functions.py | 8 +-- array_api_tests/test_data_type_functions.py | 7 +-- ...est_operators_and_elementwise_functions.py | 50 ++++++++++--------- array_api_tests/test_searching_functions.py | 5 +- array_api_tests/test_utility_functions.py | 7 ++- conftest.py | 1 + 9 files changed, 63 insertions(+), 43 deletions(-) diff --git a/array_api_tests/dtype_helpers.py b/array_api_tests/dtype_helpers.py index 6c5fa152..78d67abf 100644 --- a/array_api_tests/dtype_helpers.py +++ b/array_api_tests/dtype_helpers.py @@ -125,11 +125,16 @@ def _make_dtype_tuple_from_names(names: List[str]) -> Tuple[DataType]: dtypes.append(dtype) return tuple(dtypes) -# Numpy deprecated np.bool starting from version 1.20.0 -if xp.__name__ == "numpy" and xp.__version__ >="1.20.0": - array_mod_bool = xp.bool_ -else: - array_mod_bool = xp.bool + +def get_array_module_bool(): + # Numpy deprecated np.bool starting from version 1.20.0 + if xp.__name__ == "numpy" and xp.__version__ >="1.20.0": + return xp.bool_ + else: + return xp.bool + + +array_mod_bool = get_array_module_bool() uint_dtypes = _make_dtype_tuple_from_names(uint_names) int_dtypes = _make_dtype_tuple_from_names(int_names) diff --git a/array_api_tests/hypothesis_helpers.py b/array_api_tests/hypothesis_helpers.py index 60c683c4..4325b06b 100644 --- a/array_api_tests/hypothesis_helpers.py +++ b/array_api_tests/hypothesis_helpers.py @@ -29,10 +29,13 @@ def _float32ify(n: Union[int, float]) -> float: return struct.unpack("!f", struct.pack("!f", n))[0] +array_mod_bool = dh.get_array_module_bool() + + @wraps(xps.from_dtype) def from_dtype(dtype, **kwargs) -> SearchStrategy[Scalar]: """xps.from_dtype() without the crazy large numbers.""" - if dtype == xp.bool: + if dtype == array_mod_bool: return xps.from_dtype(dtype, **kwargs) if dtype in dh.complex_dtypes: @@ -76,7 +79,7 @@ def arrays(dtype, *args, elements=None, **kwargs) -> SearchStrategy[Array]: return xps.arrays(dtype, *args, elements=elements, **kwargs) -_dtype_categories = [(xp.bool,), dh.uint_dtypes, dh.int_dtypes, dh.real_float_dtypes, dh.complex_dtypes] +_dtype_categories = [(array_mod_bool,), dh.uint_dtypes, dh.int_dtypes, dh.real_float_dtypes, dh.complex_dtypes] _sorted_dtypes = [d for category in _dtype_categories for d in category] def _dtypes_sorter(dtype_pair: Tuple[DataType, DataType]): diff --git a/array_api_tests/test_array_object.py b/array_api_tests/test_array_object.py index bc3e7276..6c90e61a 100644 --- a/array_api_tests/test_array_object.py +++ b/array_api_tests/test_array_object.py @@ -17,6 +17,8 @@ from .typing import DataType, Index, Param, Scalar, ScalarType, Shape +array_mod_bool = dh.get_array_module_bool() + def scalar_objects( dtype: DataType, shape: Shape ) -> st.SearchStrategy[Union[Scalar, List[Scalar]]]: @@ -165,7 +167,7 @@ def test_getitem_masking(shape, data): ), hh.shapes(), ) - key = data.draw(hh.arrays(dtype=xp.bool, shape=mask_shapes), label="key") + key = data.draw(hh.arrays(dtype=array_mod_bool, shape=mask_shapes), label="key") if key.ndim > x.ndim or not all( ks in (xs, 0) for xs, ks in zip(x.shape, key.shape) @@ -203,7 +205,7 @@ def test_getitem_masking(shape, data): @given(hh.shapes(), st.data()) def test_setitem_masking(shape, data): x = data.draw(hh.arrays(xps.scalar_dtypes(), shape=shape), label="x") - key = data.draw(hh.arrays(dtype=xp.bool, shape=shape), label="key") + key = data.draw(hh.arrays(dtype=array_mod_bool, shape=shape), label="key") value = data.draw( hh.from_dtype(x.dtype) | hh.arrays(dtype=x.dtype, shape=()), label="value" ) diff --git a/array_api_tests/test_creation_functions.py b/array_api_tests/test_creation_functions.py index 6bee0533..6a35382b 100644 --- a/array_api_tests/test_creation_functions.py +++ b/array_api_tests/test_creation_functions.py @@ -75,6 +75,8 @@ def reals(min_value=None, max_value=None) -> st.SearchStrategy[Union[int, float] ), ) +array_mod_bool = dh.get_array_module_bool() + # TODO: support testing complex dtypes @given(dtype=st.none() | xps.real_dtypes(), data=st.data()) @@ -204,7 +206,7 @@ def test_asarray_scalars(shape, data): if dtype is None: dtype_family = data.draw( st.sampled_from( - [(xp.bool,), (xp.int32, xp.int64), (xp.float32, xp.float64)] + [(array_mod_bool,), (xp.int32, xp.int64), (xp.float32, xp.float64)] ), label="expected out dtypes", ) @@ -393,7 +395,7 @@ def test_full(shape, fill_value, kw): if kw.get("dtype", None): dtype = kw["dtype"] elif isinstance(fill_value, bool): - dtype = xp.bool + dtype = array_mod_bool elif isinstance(fill_value, int): dtype = dh.default_int elif isinstance(fill_value, float): @@ -410,7 +412,7 @@ def test_full(shape, fill_value, kw): assume(all(abs(c) < math.sqrt(M) for c in [fill_value.real, fill_value.imag])) if kw.get("dtype", None) is None: if isinstance(fill_value, bool): - assert out.dtype == xp.bool, f"{out.dtype=}, but should be bool [full()]" + assert out.dtype == array_mod_bool, f"{out.dtype=}, but should be bool [full()]" elif isinstance(fill_value, int): ph.assert_default_int("full", out.dtype) elif isinstance(fill_value, float): diff --git a/array_api_tests/test_data_type_functions.py b/array_api_tests/test_data_type_functions.py index 1fa8c3b6..7b95cb6f 100644 --- a/array_api_tests/test_data_type_functions.py +++ b/array_api_tests/test_data_type_functions.py @@ -23,6 +23,7 @@ def non_complex_dtypes(): def float32(n: Union[int, float]) -> float: return struct.unpack("!f", struct.pack("!f", float(n)))[0] +array_mod_bool = dh.get_array_module_bool() @given( x_dtype=non_complex_dtypes(), @@ -31,7 +32,7 @@ def float32(n: Union[int, float]) -> float: data=st.data(), ) def test_astype(x_dtype, dtype, kw, data): - if xp.bool in (x_dtype, dtype): + if array_mod_bool in (x_dtype, dtype): elements_strat = hh.from_dtype(x_dtype) else: m1, M1 = dh.dtype_ranges[x_dtype] @@ -118,8 +119,8 @@ def test_can_cast(_from, to, data): f_func = f"[can_cast({dh.dtype_to_name[_from]}, {dh.dtype_to_name[to]})]" assert isinstance(out, bool), f"{type(out)=}, but should be bool {f_func}" - if _from == xp.bool: - expected = to == xp.bool + if _from == array_mod_bool: + expected = to == array_mod_bool else: same_family = None for dtypes in [dh.all_int_dtypes, dh.real_float_dtypes, dh.complex_dtypes]: diff --git a/array_api_tests/test_operators_and_elementwise_functions.py b/array_api_tests/test_operators_and_elementwise_functions.py index 27144847..a9ad4fbd 100644 --- a/array_api_tests/test_operators_and_elementwise_functions.py +++ b/array_api_tests/test_operators_and_elementwise_functions.py @@ -47,6 +47,8 @@ def mock_int_dtype(n: int, dtype: DataType) -> int: return n +array_mod_bool = dh.get_array_module_bool() + def isclose( a: float, b: float, @@ -136,7 +138,7 @@ def unary_assert_against_refimpl( Array dtypes | Python builtin type ----------------- | --------------------- - xp.bool | bool + xp.bool, xp.bool_ | bool xp.int*, xp.uint* | int xp.float* | float xp.complex* | complex @@ -238,7 +240,7 @@ def unary_assert_against_refimpl( in_stype = dh.get_scalar_type(in_.dtype) if res_stype is None: res_stype = dh.get_scalar_type(res.dtype) - if res.dtype == xp.bool: + if res.dtype == array_mod_bool: m, M = (None, None) elif res.dtype in dh.complex_dtypes: m, M = dh.dtype_ranges[dh.dtype_components[res.dtype]] @@ -255,7 +257,7 @@ def unary_assert_against_refimpl( expected = refimpl(scalar_i) except Exception: continue - if res.dtype != xp.bool: + if res.dtype != array_mod_bool: if res.dtype in dh.complex_dtypes: if expected.real <= m or expected.real >= M: continue @@ -312,7 +314,7 @@ def binary_assert_against_refimpl( res_stype = dh.get_scalar_type(left.dtype) if res_stype is None: res_stype = in_stype - if res.dtype == xp.bool: + if res.dtype == array_mod_bool: m, M = (None, None) elif res.dtype in dh.complex_dtypes: m, M = dh.dtype_ranges[dh.dtype_components[res.dtype]] @@ -330,7 +332,7 @@ def binary_assert_against_refimpl( expected = refimpl(scalar_l, scalar_r) except Exception: continue - if res.dtype != xp.bool: + if res.dtype != array_mod_bool: if res.dtype in dh.complex_dtypes: if expected.real <= m or expected.real >= M: continue @@ -389,7 +391,7 @@ def right_scalar_assert_against_refimpl( res_stype = dh.get_scalar_type(left.dtype) if res_stype is None: res_stype = in_stype - if res.dtype == xp.bool: + if res.dtype == array_mod_bool: m, M = (None, None) elif left.dtype in dh.complex_dtypes: m, M = dh.dtype_ranges[dh.dtype_components[left.dtype]] @@ -403,7 +405,7 @@ def right_scalar_assert_against_refimpl( expected = refimpl(scalar_l, right) except Exception: continue - if left.dtype != xp.bool: + if left.dtype != array_mod_bool: if res.dtype in dh.complex_dtypes: if expected.real <= m or expected.real >= M: continue @@ -819,7 +821,7 @@ def test_bitwise_and(ctx, data): binary_param_assert_dtype(ctx, left, right, res) binary_param_assert_shape(ctx, left, right, res) - if left.dtype == xp.bool: + if left.dtype == array_mod_bool: refimpl = operator.and_ else: refimpl = lambda l, r: mock_int_dtype(l & r, res.dtype) @@ -859,7 +861,7 @@ def test_bitwise_invert(ctx, data): ph.assert_dtype(ctx.func_name, in_dtype=x.dtype, out_dtype=out.dtype) ph.assert_shape(ctx.func_name, out_shape=out.shape, expected=x.shape) - if x.dtype == xp.bool: + if x.dtype == array_mod_bool: refimpl = operator.not_ else: refimpl = lambda s: mock_int_dtype(~s, x.dtype) @@ -878,7 +880,7 @@ def test_bitwise_or(ctx, data): binary_param_assert_dtype(ctx, left, right, res) binary_param_assert_shape(ctx, left, right, res) - if left.dtype == xp.bool: + if left.dtype == array_mod_bool: refimpl = operator.or_ else: refimpl = lambda l, r: mock_int_dtype(l | r, res.dtype) @@ -918,7 +920,7 @@ def test_bitwise_xor(ctx, data): binary_param_assert_dtype(ctx, left, right, res) binary_param_assert_shape(ctx, left, right, res) - if left.dtype == xp.bool: + if left.dtype == array_mod_bool: refimpl = operator.xor else: refimpl = lambda l, r: mock_int_dtype(l ^ r, res.dtype) @@ -992,7 +994,7 @@ def test_equal(ctx, data): out = ctx.func(left, right) - binary_param_assert_dtype(ctx, left, right, out, xp.bool) + binary_param_assert_dtype(ctx, left, right, out, array_mod_bool) binary_param_assert_shape(ctx, left, right, out) if not ctx.right_is_scalar: # We manually promote the dtypes as incorrect internal type promotion @@ -1063,7 +1065,7 @@ def test_greater(ctx, data): out = ctx.func(left, right) - binary_param_assert_dtype(ctx, left, right, out, xp.bool) + binary_param_assert_dtype(ctx, left, right, out, array_mod_bool) binary_param_assert_shape(ctx, left, right, out) if not ctx.right_is_scalar: # See test_equal note @@ -1083,7 +1085,7 @@ def test_greater_equal(ctx, data): out = ctx.func(left, right) - binary_param_assert_dtype(ctx, left, right, out, xp.bool) + binary_param_assert_dtype(ctx, left, right, out, array_mod_bool) binary_param_assert_shape(ctx, left, right, out) if not ctx.right_is_scalar: # See test_equal note @@ -1108,7 +1110,7 @@ def test_imag(x): @given(hh.arrays(dtype=xps.numeric_dtypes(), shape=hh.shapes())) def test_isfinite(x): out = xp.isfinite(x) - ph.assert_dtype("isfinite", in_dtype=x.dtype, out_dtype=out.dtype, expected=xp.bool) + ph.assert_dtype("isfinite", in_dtype=x.dtype, out_dtype=out.dtype, expected=array_mod_bool) ph.assert_shape("isfinite", out_shape=out.shape, expected=x.shape) unary_assert_against_refimpl("isfinite", x, out, math.isfinite, res_stype=bool) @@ -1116,7 +1118,7 @@ def test_isfinite(x): @given(hh.arrays(dtype=xps.numeric_dtypes(), shape=hh.shapes())) def test_isinf(x): out = xp.isinf(x) - ph.assert_dtype("isfinite", in_dtype=x.dtype, out_dtype=out.dtype, expected=xp.bool) + ph.assert_dtype("isfinite", in_dtype=x.dtype, out_dtype=out.dtype, expected=array_mod_bool) ph.assert_shape("isinf", out_shape=out.shape, expected=x.shape) unary_assert_against_refimpl("isinf", x, out, math.isinf, res_stype=bool) @@ -1124,7 +1126,7 @@ def test_isinf(x): @given(hh.arrays(dtype=xps.numeric_dtypes(), shape=hh.shapes())) def test_isnan(x): out = xp.isnan(x) - ph.assert_dtype("isnan", in_dtype=x.dtype, out_dtype=out.dtype, expected=xp.bool) + ph.assert_dtype("isnan", in_dtype=x.dtype, out_dtype=out.dtype, expected=array_mod_bool) ph.assert_shape("isnan", out_shape=out.shape, expected=x.shape) unary_assert_against_refimpl("isnan", x, out, math.isnan, res_stype=bool) @@ -1137,7 +1139,7 @@ def test_less(ctx, data): out = ctx.func(left, right) - binary_param_assert_dtype(ctx, left, right, out, xp.bool) + binary_param_assert_dtype(ctx, left, right, out, array_mod_bool) binary_param_assert_shape(ctx, left, right, out) if not ctx.right_is_scalar: # See test_equal note @@ -1157,7 +1159,7 @@ def test_less_equal(ctx, data): out = ctx.func(left, right) - binary_param_assert_dtype(ctx, left, right, out, xp.bool) + binary_param_assert_dtype(ctx, left, right, out, array_mod_bool) binary_param_assert_shape(ctx, left, right, out) if not ctx.right_is_scalar: # See test_equal note @@ -1221,7 +1223,7 @@ def test_logaddexp(x1, x2): binary_assert_against_refimpl("logaddexp", x1, x2, out, logaddexp) -@given(*hh.two_mutual_arrays([xp.bool])) +@given(*hh.two_mutual_arrays([array_mod_bool])) def test_logical_and(x1, x2): out = xp.logical_and(x1, x2) ph.assert_dtype("logical_and", in_dtype=[x1.dtype, x2.dtype], out_dtype=out.dtype) @@ -1231,7 +1233,7 @@ def test_logical_and(x1, x2): ) -@given(hh.arrays(dtype=xp.bool, shape=hh.shapes())) +@given(hh.arrays(dtype=array_mod_bool, shape=hh.shapes())) def test_logical_not(x): out = xp.logical_not(x) ph.assert_dtype("logical_not", in_dtype=x.dtype, out_dtype=out.dtype) @@ -1241,7 +1243,7 @@ def test_logical_not(x): ) -@given(*hh.two_mutual_arrays([xp.bool])) +@given(*hh.two_mutual_arrays([array_mod_bool])) def test_logical_or(x1, x2): out = xp.logical_or(x1, x2) ph.assert_dtype("logical_or", in_dtype=[x1.dtype, x2.dtype], out_dtype=out.dtype) @@ -1251,7 +1253,7 @@ def test_logical_or(x1, x2): ) -@given(*hh.two_mutual_arrays([xp.bool])) +@given(*hh.two_mutual_arrays([array_mod_bool])) def test_logical_xor(x1, x2): out = xp.logical_xor(x1, x2) ph.assert_dtype("logical_xor", in_dtype=[x1.dtype, x2.dtype], out_dtype=out.dtype) @@ -1300,7 +1302,7 @@ def test_not_equal(ctx, data): out = ctx.func(left, right) - binary_param_assert_dtype(ctx, left, right, out, xp.bool) + binary_param_assert_dtype(ctx, left, right, out, array_mod_bool) binary_param_assert_shape(ctx, left, right, out) if not ctx.right_is_scalar: # See test_equal note diff --git a/array_api_tests/test_searching_functions.py b/array_api_tests/test_searching_functions.py index ee7d4e9b..6c41a2be 100644 --- a/array_api_tests/test_searching_functions.py +++ b/array_api_tests/test_searching_functions.py @@ -14,6 +14,7 @@ pytestmark = pytest.mark.unvectorized +array_mod_bool = dh.get_array_module_bool() @given( x=hh.arrays( @@ -109,7 +110,7 @@ def test_nonzero(x): ) ph.assert_default_index("nonzero", out[i].dtype, repr_name=f"out[{i}].dtype") indices = [] - if x.dtype == xp.bool: + if x.dtype == array_mod_bool: for idx in sh.ndindex(x.shape): if x[idx]: indices.append(idx) @@ -138,7 +139,7 @@ def test_nonzero(x): data=st.data(), ) def test_where(shapes, dtypes, data): - cond = data.draw(hh.arrays(dtype=xp.bool, shape=shapes[0]), label="condition") + cond = data.draw(hh.arrays(dtype=array_mod_bool, shape=shapes[0]), label="condition") x1 = data.draw(hh.arrays(dtype=dtypes[0], shape=shapes[1]), label="x1") x2 = data.draw(hh.arrays(dtype=dtypes[1], shape=shapes[2]), label="x2") diff --git a/array_api_tests/test_utility_functions.py b/array_api_tests/test_utility_functions.py index e094cfb9..420006ca 100644 --- a/array_api_tests/test_utility_functions.py +++ b/array_api_tests/test_utility_functions.py @@ -10,6 +10,9 @@ from . import xps +array_mod_bool = dh.get_array_module_bool() + + @pytest.mark.unvectorized @given( x=hh.arrays(dtype=xps.scalar_dtypes(), shape=hh.shapes(min_side=1)), @@ -21,7 +24,7 @@ def test_all(x, data): out = xp.all(x, **kw) - ph.assert_dtype("all", in_dtype=x.dtype, out_dtype=out.dtype, expected=xp.bool) + ph.assert_dtype("all", in_dtype=x.dtype, out_dtype=out.dtype, expected=array_mod_bool) _axes = sh.normalise_axis(kw.get("axis", None), x.ndim) ph.assert_keepdimable_shape( "all", in_shape=x.shape, out_shape=out.shape, axes=_axes, keepdims=keepdims, kw=kw @@ -49,7 +52,7 @@ def test_any(x, data): out = xp.any(x, **kw) - ph.assert_dtype("any", in_dtype=x.dtype, out_dtype=out.dtype, expected=xp.bool) + ph.assert_dtype("any", in_dtype=x.dtype, out_dtype=out.dtype, expected=array_mod_bool) _axes = sh.normalise_axis(kw.get("axis", None), x.ndim) ph.assert_keepdimable_shape( "any", in_shape=x.shape, out_shape=out.shape, axes=_axes, keepdims=keepdims, kw=kw, diff --git a/conftest.py b/conftest.py index 4952bcee..540e62fb 100644 --- a/conftest.py +++ b/conftest.py @@ -15,6 +15,7 @@ from reporting import pytest_metadata, pytest_json_modifyreport, add_extra_json_metadata # noqa +os.environ["ARRAY_API_TESTS_MODULE"]="numpy" def pytest_addoption(parser): # Hypothesis max examples From d4a4d4d942b0b0dd457f513881161bdcc1eb098b Mon Sep 17 00:00:00 2001 From: hirwa Date: Mon, 8 Apr 2024 13:14:41 +0530 Subject: [PATCH 3/5] remove extra conftest config --- array_api_tests/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/array_api_tests/__init__.py b/array_api_tests/__init__.py index 9af6796b..5a0a1375 100644 --- a/array_api_tests/__init__.py +++ b/array_api_tests/__init__.py @@ -9,6 +9,7 @@ __all__ = ["xp", "api_version", "xps"] +os.environ["ARRAY_API_TESTS_MODULE"] = "numpy" # You can comment the following out and instead import the specific array module # you want to test, e.g. `import numpy.array_api as xp`. From 2ff2ff2caffc63f2a2f61de81ae4aeb0f3df8113 Mon Sep 17 00:00:00 2001 From: hirwa Date: Tue, 9 Apr 2024 09:04:14 +0530 Subject: [PATCH 4/5] added numpy 2.0.0 to the check as it will support np.bool --- array_api_tests/__init__.py | 1 - array_api_tests/dtype_helpers.py | 10 ++++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/array_api_tests/__init__.py b/array_api_tests/__init__.py index 5a0a1375..9af6796b 100644 --- a/array_api_tests/__init__.py +++ b/array_api_tests/__init__.py @@ -9,7 +9,6 @@ __all__ = ["xp", "api_version", "xps"] -os.environ["ARRAY_API_TESTS_MODULE"] = "numpy" # You can comment the following out and instead import the specific array module # you want to test, e.g. `import numpy.array_api as xp`. diff --git a/array_api_tests/dtype_helpers.py b/array_api_tests/dtype_helpers.py index 78d67abf..946c646f 100644 --- a/array_api_tests/dtype_helpers.py +++ b/array_api_tests/dtype_helpers.py @@ -4,6 +4,7 @@ from functools import lru_cache from typing import Any, DefaultDict, Dict, List, NamedTuple, Sequence, Tuple, Union from warnings import warn +from packaging import version from . import api_version from . import xp @@ -128,10 +129,11 @@ def _make_dtype_tuple_from_names(names: List[str]) -> Tuple[DataType]: def get_array_module_bool(): # Numpy deprecated np.bool starting from version 1.20.0 - if xp.__name__ == "numpy" and xp.__version__ >="1.20.0": - return xp.bool_ - else: - return xp.bool + if xp.__name__ == "numpy": + xp_version = version.parse(xp.__version__) + if xp_version >= version.parse("1.20.0") and xp_version < version.parse("2.0.0"): + return xp.bool_ + return xp.bool array_mod_bool = get_array_module_bool() From 308e384911668ed560d65af12b356cc9076d5961 Mon Sep 17 00:00:00 2001 From: hirwa Date: Tue, 9 Apr 2024 09:05:58 +0530 Subject: [PATCH 5/5] remove redundant conftest code --- conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/conftest.py b/conftest.py index 540e62fb..4952bcee 100644 --- a/conftest.py +++ b/conftest.py @@ -15,7 +15,6 @@ from reporting import pytest_metadata, pytest_json_modifyreport, add_extra_json_metadata # noqa -os.environ["ARRAY_API_TESTS_MODULE"]="numpy" def pytest_addoption(parser): # Hypothesis max examples