diff options
Diffstat (limited to 'numpy/_array_api')
-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', |