Skip to content

BUG: broken comparison between ndarray subclass (unyt) and strings #22744

@neutrinoceros

Description

@neutrinoceros

Describe the issue:

19ba7c4 (#22707) broke string comparison between unyt.unyt_quantity object (fancy 0d numpy arrays with unit data), and strings.

The following minimal example used to be fine, but it crashes on the main branch of numpy

Reproduce the code example:

import unyt as un

a = 1 * un.cm
assert a != "hello"

Error message:

-traceback
Traceback (most recent call last):
  File "/Users/robcleme/dev/numpy/t.py", line 4, in <module>
    assert a != "hello"
           ^^^^^^^^^^^^
  File "/Users/robcleme/.pyenv/versions/numpy-dev/lib/python3.11/site-packages/unyt/array.py", line 1850, in __array_ufunc__
    new_dtype = np.dtype("f" + str(inp1.dtype.itemsize))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: data type 'f20' not understood

NumPy/Python version information:

Python 3.11.0

Context for the issue:

This change of behaviour breaks yt, see yt-project/yt#4241
I note that we haven't captured this regression via unyt's on CI, so I'll add a test there. (edit: this is yt-project/unyt#333)

It is unclear to me why this is happening, and I am not sure which of numpy or unyt this bug should be fixed in.

Ping @ngoldbaum for information

Metadata

Metadata

Assignees

No one assigned

    Labels

    00 - Bug57 - Close?Issues which may be closable unless discussion continued

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions