BUG Numpy ufunc binop fix for subclasses with __numpy_ufunc__ (closes #4815) by mhvk · Pull Request #5748 · numpy/numpy
and others added 3 commits
April 4, 2015 21:47These changes only affect objects defining __numpy_ufunc__. Other
objects use the __array_priority__ mechanism to decide whether
NotImplemented should be returned or not.
The binops previously returned NotImplemented even if other._r<op>__ is
ndarray.__r<op>__, rather than trying to evaluate the result via ufuncs.
This causes problems in binops of two objects that both subclass from
ndarray and define __numpy_ufunc__.
The solution added here makes the total logic as follows:
def __binop__(self, other):
if (hasattr(other, '__numpy_ufunc__') and
not isinstance(other, self.__class__) and
hasattr(other, '__rop__') and
other.__class__.__rop__ is not self.__class__.__rop__):
return NotImplemented
return np.binop(self, other)
mhvk
mentioned this pull request
charris
added this to the
1.10.0 release milestone
charris added a commit that referenced this pull request
May 6, 2015BUG Numpy ufunc binop fix for subclasses with __numpy_ufunc__ (closes #4815)
mhvk
deleted the
numpyufunc-binop-fix
branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters