diff options
author | Aaron Meurer <asmeurer@gmail.com> | 2021-07-22 18:19:59 -0600 |
---|---|---|
committer | Aaron Meurer <asmeurer@gmail.com> | 2021-07-22 18:20:37 -0600 |
commit | deaf0bf6fc819c9c7b4dcffe0d4aee43bdc33bae (patch) | |
tree | 29c1a7b8d1fe39f7535960ce8df519d42c6db2d2 /numpy | |
parent | 64bb971096892c08416c5787d705a29bcd5b64b5 (diff) | |
download | numpy-deaf0bf6fc819c9c7b4dcffe0d4aee43bdc33bae.tar.gz |
Fix the array API __abs__() to restrict to numeric dtypes
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/_array_api/_array_object.py | 2 | ||||
-rw-r--r-- | numpy/_array_api/tests/test_array_object.py | 1 |
2 files changed, 3 insertions, 0 deletions
diff --git a/numpy/_array_api/_array_object.py b/numpy/_array_api/_array_object.py index 98e2f78f9..cd16f49ee 100644 --- a/numpy/_array_api/_array_object.py +++ b/numpy/_array_api/_array_object.py @@ -317,6 +317,8 @@ class Array: """ Performs the operation __abs__. """ + if self.dtype not in _numeric_dtypes: + raise TypeError('Only numeric dtypes are allowed in __abs__') res = self._array.__abs__() return self.__class__._new(res) diff --git a/numpy/_array_api/tests/test_array_object.py b/numpy/_array_api/tests/test_array_object.py index 25802f93c..22078bbee 100644 --- a/numpy/_array_api/tests/test_array_object.py +++ b/numpy/_array_api/tests/test_array_object.py @@ -166,6 +166,7 @@ def test_operators(): assert_raises(TypeError, lambda: getattr(x, _op)(y)) unary_op_dtypes ={ + '__abs__': 'numeric', '__invert__': 'integer_or_boolean', '__neg__': 'numeric', '__pos__': 'numeric', |