Skip to content

BUG: np.equal does not work where == does  #4470

Closed

Description

@abalkin
>>> import numpy as np
>>> x = np.array('abc', 'c')
>>> x == x
array([ True,  True,  True], dtype=bool)
>>> np.equal(x, x)
NotImplemented

Activity

  1. ddasilva commented on Mar 15, 2014

    @ddasilva
    Contributor

    I took a look at this. Both use the equal ufunc. However, x==x goes through array_richcompare() first, and array_richcompare() has extra code that is recovering from the failure.

    The end of array_richcompare() (arrayobject.c, line 1433):

        if (result == Py_NotImplemented) {
            /* Try to handle string comparisons */
            ...
        }
        return result;
    
  2. abalkin commented on Apr 7, 2014

    @abalkin
    ContributorAuthor

    So it appears that the underlying problem is that ufuncs do not work with flex arrays. For example,

    >>> x = numpy.zeros(1, dtype='d,d')
    >>> numpy.add(x, x)
    NotImplemented
    
  3. charris commented on Aug 16, 2019

    @charris
    Member

    See also

    #4470
    #3322
    #3015

  4. seberg commented on Jan 28, 2024

    @seberg
    Member

    Going to close this, while still true in some other cases, it isn't for strings since 1.25 or so.

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions