MCPcopy Create free account
hub / github.com/numpy/numpy / test_asarray_errors

Function test_asarray_errors

numpy/array_api/tests/test_creation_functions.py:24–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23
24def test_asarray_errors():
25 # Test various protections against incorrect usage
26 assert_raises(TypeError, lambda: Array([1]))
27 assert_raises(TypeError, lambda: asarray(["a"]))
28 assert_raises(ValueError, lambda: asarray([1.0], dtype=np.float16))
29 assert_raises(OverflowError, lambda: asarray(2**100))
30 # Preferably this would be OverflowError
31 # assert_raises(OverflowError, lambda: asarray([2**100]))
32 assert_raises(TypeError, lambda: asarray([2**100]))
33 asarray([1], device="cpu") # Doesn't error
34 assert_raises(ValueError, lambda: asarray([1], device="gpu"))
35
36 assert_raises(ValueError, lambda: asarray([1], dtype=int))
37 assert_raises(ValueError, lambda: asarray([1], dtype="i"))
38
39
40def test_asarray_copy():

Callers

nothing calls this directly

Calls 3

assert_raisesFunction · 0.90
ArrayClass · 0.50
asarrayFunction · 0.50

Tested by

no test coverage detected