diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-07-22 17:04:24 -0600 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-07-22 17:04:24 -0600 |
commit | 64bb971096892c08416c5787d705a29bcd5b64b5 (patch) | |
tree | b28ad31288f6881446ea0e059cfcb8505596eac2 /numpy | |
parent | 1e835f9f70a3cba6fc7a053edcbd1b1a01ee79b4 (diff) | |
download | numpy-64bb971096892c08416c5787d705a29bcd5b64b5.tar.gz |
Add tests for Python scalar constructors on array API arrays
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/_array_api/tests/test_array_object.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/numpy/_array_api/tests/test_array_object.py b/numpy/_array_api/tests/test_array_object.py index 5aba2b23c..25802f93c 100644 --- a/numpy/_array_api/tests/test_array_object.py +++ b/numpy/_array_api/tests/test_array_object.py @@ -233,3 +233,17 @@ def test_operators(): assert_raises(ValueError, lambda: x.__imatmul__(y)) else: x.__imatmul__(y) + +def test_python_scalar_construtors(): + a = asarray(False) + b = asarray(0) + c = asarray(0.) + + assert bool(a) == bool(b) == bool(c) == False + assert int(a) == int(b) == int(c) == 0 + assert float(a) == float(b) == float(c) == 0. + + # bool/int/float should only be allowed on 0-D arrays. + assert_raises(TypeError, lambda: bool(asarray([False]))) + assert_raises(TypeError, lambda: int(asarray([0]))) + assert_raises(TypeError, lambda: float(asarray([0.]))) |