summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2017-03-12 14:56:44 -0400
committerCharles Harris <charlesr.harris@gmail.com>2017-04-27 13:25:49 -0600
commite4b51639bc4715a8d27e5449e498d6a2fe510f39 (patch)
tree6b97e88605e2b96fec3fa013df6edc200267d45c /numpy/ma
parent7d9bc2fd597236e7490b804948856bb65f4f9d3a (diff)
downloadnumpy-e4b51639bc4715a8d27e5449e498d6a2fe510f39.tar.gz
MAINT: allow __array_ufunc__ = None to force binops to defer.
In previous versions, one could force ndarray binops to defer by setting a high __array_priority__. With __array_ufunc__ this gets ignored, and this commit ensures it is still possible to avoid using the standard python language feature that setting something to None means it is not implemented. In consequence, inside a ufunc, if __array_ufunc__ is None, it will be treated as if it had returned NotImplemented (leading to a TypeError if no other object had a functioning __array_ufunc__ override).
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 51b172082..cb0bfdde2 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -3936,13 +3936,14 @@ class MaskedArray(ndarray):
# private/binop_override.h:forward_binop_should_defer
if isinstance(other, type(self)):
return False
- if not hasattr(other, "__array_ufunc__"):
+ array_ufunc = getattr(other, "__array_ufunc__", False)
+ if array_ufunc is False:
other_priority = getattr(other, "__array_priority__", -1000000)
- if self.__array_priority__ < other_priority:
- return True
- if other.__class__.__module__.startswith("scipy.sparse"):
- return True
- return False
+ return self.__array_priority__ < other_priority
+ else:
+ # If array_ufunc is not None, it will be called inside the ufunc;
+ # None explicitly tells us to not call the ufunc, i.e., defer.
+ return array_ufunc is None
def _comparison(self, other, compare):
"""Compare self with other using operator.eq or operator.ne.