summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_mixins.py
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@gmail.com>2017-04-27 12:17:06 -0700
committerCharles Harris <charlesr.harris@gmail.com>2017-04-27 13:37:51 -0600
commit32221dfb553980e34a398c71891c7dcdfaf2f477 (patch)
tree7ec8fceb73ae19451d75ff104c19f4d43fcd0ce9 /numpy/lib/tests/test_mixins.py
parent3272a860129a7192a0e499c59e273da3dd35d998 (diff)
downloadnumpy-32221dfb553980e34a398c71891c7dcdfaf2f477.tar.gz
ENH: NDArrayOperatorsMixin calls ufuncs directly, like ndarray
* ENH: NDArrayOperatorsMixin calls ufuncs directly, like ndarray Per our discussion in https://github.com/numpy/numpy/pull/8247#discussion_r112825050 * add back in accidentally dropped __repr__
Diffstat (limited to 'numpy/lib/tests/test_mixins.py')
-rw-r--r--numpy/lib/tests/test_mixins.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/numpy/lib/tests/test_mixins.py b/numpy/lib/tests/test_mixins.py
index bca974fc5..57c4a4cd8 100644
--- a/numpy/lib/tests/test_mixins.py
+++ b/numpy/lib/tests/test_mixins.py
@@ -26,18 +26,14 @@ class ArrayLike(np.lib.mixins.NDArrayOperatorsMixin):
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
out = kwargs.get('out', ())
for x in inputs + out:
- # Only support operations with instances of _HANDLED_TYPES,
- # or instances of ArrayLike that are superclasses of this
- # object's type.
- if not (isinstance(x, self._HANDLED_TYPES) or
- (isinstance(x, ArrayLike) and
- isinstance(self, type(x)))):
+ # Only support operations with instances of _HANDLED_TYPES.
+ # Use ArrayLike instead of type(self) for isinstance to
+ # allow subclasses that don't override __array_ufunc__ to
+ # handle ArrayLike objects.
+ if not isinstance(x, self._HANDLED_TYPES + (ArrayLike,)):
return NotImplemented
# Defer to the implementation of the ufunc on unwrapped values.
- # Use ArrayLike instead of type(self) for isinstance to allow
- # subclasses that don't override __array_ufunc__ to handle
- # ArrayLike objects.
inputs = tuple(x.value if isinstance(x, ArrayLike) else x
for x in inputs)
if out:
@@ -136,11 +132,12 @@ class TestNDArrayOperatorsMixin(TestCase):
def test_object(self):
x = ArrayLike(0)
obj = object()
- assert_equal(x.__add__(obj), NotImplemented)
with assert_raises(TypeError):
x + obj
with assert_raises(TypeError):
obj + x
+ with assert_raises(TypeError):
+ x += obj
def test_unary_methods(self):
array = np.array([-1, 0, 1, 2])