Skip to content

operator.eq works on string arrays, but not np.equal does not #6122

Closed

Description

@shoyer

This is on numpy 1.9.2 (I'm having trouble building on master right now):

In [1]: import numpy as np

In [2]: x = np.array(['foo'])

In [3]: x
Out[3]:
array(['foo'],
      dtype='|S3')

In [4]: np.equal(x, x)
Out[4]: NotImplemented

In [5]: x == x
Out[5]: array([ True], dtype=bool)

This is slightly disconcerting, especially given that we were considering delegating all binary operations to the corresponding NumPy ufuncs in #5844.

Activity

  1. njsmith commented on Jul 27, 2015

    @njsmith
    Member

    Yeah, this is because string dtypes are stateful, and as you may have heard
    ;-), it's not currently possible to define ufuncs for stateful dtypes.
    (Instead we have a hack inside ndarray.eq that special cases string
    dtypes, quelle awesome.) So this is blocked on fixing ufuncs.
    On Jul 26, 2015 9:20 PM, "Stephan Hoyer" [email protected] wrote:

    This is on numpy 1.9.2 (I'm having trouble building on master right now):

    In [1]: import numpy as np

    In [2]: x = np.array(['foo'])

    In [3]: x
    Out[3]:
    array(['foo'],
    dtype='|S3')

    In [4]: np.equal(x, x)
    Out[4]: NotImplemented

    In [5]: x == x
    Out[5]: array([ True], dtype=bool)

    This is slightly disconcerting, especially given that we were
    considering delegating all binary operations to the corresponding NumPy
    ufuncs in #5844 #5844.

    —
    Reply to this email directly or view it on GitHub
    #6122.

  2. seberg commented on Jun 8, 2023

    @seberg
    Member

    Closing, it works now and the weirdness about NotImplemented has been fixed many years ago (structured dtypes are still special for the moment, admittedly)

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