From 14aebfd7a2a3fc62238a9731a63a5d2b2fc2f0c1 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Mon, 30 Oct 2023 11:04:36 +0000 Subject: [PATCH] test: add test --- tests/test_2793_nep_70_gradual_support.py | 29 +++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/test_2793_nep_70_gradual_support.py b/tests/test_2793_nep_70_gradual_support.py index 06a3977793..9747d0a093 100644 --- a/tests/test_2793_nep_70_gradual_support.py +++ b/tests/test_2793_nep_70_gradual_support.py @@ -1,4 +1,5 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE +import contextlib import numpy as np import packaging.version @@ -11,22 +12,30 @@ ) -@pytest.mark.skipif(NUMPY_HAS_NEP_50, reason="NEP-50 requires NumPy >= 1.24.0") -def test_with_nep_50(): - array = ak.from_numpy(np.arange(255, dtype=np.uint8)) +@pytest.mark.skipif(not NUMPY_HAS_NEP_50, reason="NEP-50 requires NumPy >= 1.24.0") +@pytest.mark.parametrize("backend", ["cpu", "typetracer"]) +def test_with_nep_50(backend): + array = ak.to_backend(np.arange(255, dtype=np.uint8), backend) assert array.layout.dtype == np.dtype(np.uint8) typed_scalar = np.uint64(0) assert (array + typed_scalar).layout.dtype == np.dtype(np.uint64) # With NEP-50, we can ask NumPy to use value-less type resolution - untyped_scalar = 512 - assert (array + untyped_scalar).layout.dtype == np.dtype(np.uint8) - - -@pytest.mark.skipif(not NUMPY_HAS_NEP_50, reason="NumPy >= 1.24.0 has NEP-50 support") -def test_without_nep_50(): - array = ak.from_numpy(np.arange(255, dtype=np.uint8)) + warn_context = ( + pytest.warns(DeprecationWarning, match="out-of-bound Python integers") + if backend == "cpu" + else contextlib.nullcontext() + ) + with warn_context: + untyped_scalar = 512 + assert (array + untyped_scalar).layout.dtype == np.dtype(np.uint8) + + +@pytest.mark.skipif(NUMPY_HAS_NEP_50, reason="NumPy >= 1.24.0 has NEP-50 support") +@pytest.mark.parametrize("backend", ["cpu", "typetracer"]) +def test_without_nep_50(backend): + array = ak.to_backend(np.arange(255, dtype=np.uint8), backend) assert array.layout.dtype == np.dtype(np.uint8) # Without NEP-50, we still don't drop type information for typed-scalars,