You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
functions return NotImplemented instead of raising error (Trac #1494) #2091
All of the Numpy functions that I mentioned above were all ufuncs that took two arguments. There was some code for handling errors in ufunc_object.c that returned Py_NotImplemented when there were two arguments to the function rather than raising the NotImplemented exception. The comment by this code said 'To allow the other argument to be given a chance'. I don't see how that comment makes any sense. Does anyone know why this is in there?
The patch I submitted removes these lines so that the correct exception is raised.
The problem here comes from conflating Python binop interface with ufuncs, and the best fix would be just move the NotImplemented returns into the binop layer. Ufuncs themselves should likely raise TypeErrors in the cases where they currently return NotImplemented.
Activity
thouis commentedon Oct 19, 2012
trac user jpeel wrote on 2011-01-04
The sqrt and log in examples above appear to be fixed in 2.0.0.dev-9451260. However, the following Numpy functions still have this problem:
power, add, subtract, multiply, divide, bitwise_and, bitwise_or, bitwise_xor, floor_divide, fmax, fmin, fmod, greater, greater_equal, hypot, less, less_equal, logaddexp, logaddexp2, logical_and, logical_or, logical_xor, maximum, minimum, mod, and not_equal.
thouis commentedon Oct 19, 2012
Attachment added by trac user jpeel on 2011-01-04: 0001-BF-fix-for-raising-NotImplemented-rather-than-return.patch
thouis commentedon Oct 19, 2012
trac user jpeel wrote on 2011-01-04
All of the Numpy functions that I mentioned above were all ufuncs that took two arguments. There was some code for handling errors in ufunc_object.c that returned Py_NotImplemented when there were two arguments to the function rather than raising the NotImplemented exception. The comment by this code said 'To allow the other argument to be given a chance'. I don't see how that comment makes any sense. Does anyone know why this is in there?
The patch I submitted removes these lines so that the correct exception is raised.
charris commentedon Feb 19, 2014
Still a problem, patch should be applied.
ddasilva commentedon Mar 15, 2014
When supplied patch is applied to current master (
17227ce130cae09f) running the tests leads to errors, failures and eventually segfaults.ddasilva commentedon Mar 16, 2014
I will also add that there is some behavior in NumPy that is dependent on ufunc's returning
NotImplemented. See comment in #4470.abalkin commentedon Apr 7, 2014
This issue is exacerbated by the fact that NotImplemented is happily wrapped in an (object) array:
this leads to hard to debug errors that occur long after the operands that resulted in NotImplemented are gone.
Maybe
np.array(NotImplemented)should be an error.charris commentedon Apr 7, 2014
Whoa, nasty.
pv commentedon Apr 7, 2014
The problem here comes from conflating Python binop interface with ufuncs, and the best fix would be just move the NotImplemented returns into the binop layer. Ufuncs themselves should likely raise TypeErrors in the cases where they currently return NotImplemented.
seberg commentedon Apr 7, 2014
I think simply changing this may be possible in master. AFAIK we now should be checking the binop explicitly first.
njsmith commentedon Jun 22, 2015
This has been dealt with by #5964 / #5864.