Skip to content

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

Closed

Description

@thouis

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

Activity

  1. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

    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.

  2. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

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

  3. thouis commented on Oct 19, 2012

    @thouis
    ContributorAuthor

    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.

  4. charris commented on Feb 19, 2014

    @charris
    Member

    Still a problem, patch should be applied.

  5. ddasilva commented on Mar 15, 2014

    @ddasilva
    Contributor

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

  6. ddasilva commented on Mar 16, 2014

    @ddasilva
    Contributor

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

  7. abalkin commented on Apr 7, 2014

    @abalkin
    Contributor

    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.

  8. charris commented on Apr 7, 2014

    @charris
    Member

    Whoa, nasty.

  9. pv commented on Apr 7, 2014

    @pv
    Member

    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.

  10. seberg commented on Apr 7, 2014

    @seberg
    Member

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

  11. njsmith commented on Jun 22, 2015

    @njsmith
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions