Thanks to visit codestin.com
Credit goes to github.com

Skip to content

functions return NotImplemented instead of raising error (Trac #1494) #2091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
thouis opened this issue Oct 19, 2012 · 11 comments
Closed

functions return NotImplemented instead of raising error (Trac #1494) #2091

thouis opened this issue Oct 19, 2012 · 11 comments

Comments

@thouis
Copy link
Contributor

thouis commented Oct 19, 2012

Original ticket http://projects.scipy.org/numpy/ticket/1494 on 2010-05-27 by @josef-pkt, assigned to unknown.

examples:

>>> np.sqrt('5')
NotImplemented
>>> a = np.sqrt('5')
>>> type(a)
<type 'NotImplementedType'>



>>> np.log(np.array(['5']))
NotImplemented
>>> np.power(np.array(['5']),5)
NotImplemented
>>> np.multiply(np.array(['5']),5)
NotImplemented
@thouis
Copy link
Contributor Author

thouis commented 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
Copy link
Contributor Author

thouis commented Oct 19, 2012

Attachment added by trac user jpeel on 2011-01-04: 0001-BF-fix-for-raising-NotImplemented-rather-than-return.patch

@thouis
Copy link
Contributor Author

thouis commented 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
Copy link
Member

charris commented Feb 19, 2014

Still a problem, patch should be applied.

@ddasilva
Copy link
Contributor

When supplied patch is applied to current master (17227ce130cae09f) running the tests leads to errors, failures and eventually segfaults.

@ddasilva
Copy link
Contributor

I will also add that there is some behavior in NumPy that is dependent on ufunc's returning NotImplemented. See comment in #4470.

@abalkin
Copy link
Contributor

abalkin commented Apr 7, 2014

This issue is exacerbated by the fact that NotImplemented is happily wrapped in an (object) array:

>>> np.array(NotImplemented)
array(NotImplemented, dtype=object)

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
Copy link
Member

charris commented Apr 7, 2014

Whoa, nasty.

@pv
Copy link
Member

pv commented 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
Copy link
Member

seberg commented Apr 7, 2014

I think simply changing this may be possible in master. AFAIK we now should be checking the binop explicitly first.

@njsmith
Copy link
Member

njsmith commented Jun 22, 2015

This has been dealt with by #5964 / #5864.

@njsmith njsmith closed this as completed Jun 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants