Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Oct 30, 2023
1 parent b7c359b commit 14aebfd
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions tests/test_2793_nep_70_gradual_support.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 14aebfd

Please sign in to comment.