diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-03-02 16:10:01 -0700 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-03-02 16:10:01 -0700 |
commit | 63be085194ddf9d2d8fc32a0ccbe30936c78d870 (patch) | |
tree | 00356db91b2f440231bf48946257c9b499c83837 /numpy/_array_api/_array_object.py | |
parent | f1f9dca83213aa4b0e6495900482f1a180a014ae (diff) | |
download | numpy-63be085194ddf9d2d8fc32a0ccbe30936c78d870.tar.gz |
Only allow __bool__, __int__, and __float__ on arrays with shape ()
Diffstat (limited to 'numpy/_array_api/_array_object.py')
-rw-r--r-- | numpy/_array_api/_array_object.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/numpy/_array_api/_array_object.py b/numpy/_array_api/_array_object.py index 23f8ab333..32a7bc9a8 100644 --- a/numpy/_array_api/_array_object.py +++ b/numpy/_array_api/_array_object.py @@ -83,6 +83,9 @@ class ndarray: """ Performs the operation __bool__. """ + # Note: This is an error here. + if x._array.shape != (): + raise TypeError("bool is only allowed on arrays with shape ()") res = x._array.__bool__() return res @@ -111,6 +114,9 @@ class ndarray: """ Performs the operation __float__. """ + # Note: This is an error here. + if x._array.shape != (): + raise TypeError("bool is only allowed on arrays with shape ()") res = x._array.__float__() return res @@ -146,6 +152,9 @@ class ndarray: """ Performs the operation __int__. """ + # Note: This is an error here. + if x._array.shape != (): + raise TypeError("bool is only allowed on arrays with shape ()") res = x._array.__int__() return res |