Skip to content

Elementwise equality comparison with zero-length void dtype fails on NumPy 1.21 #19305

@shoyer

Description

@shoyer

Reproducing code example:

With NumPy 1.21:

>>> import numpy as np
>>> x = np.zeros((3,), np.void)
>>> x == x
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:4: FutureWarning: elementwise == comparison failed and returning scalar instead; this will raise an error or perform elementwise comparison in the future.
False

I believe the error comes from these lines:

_res = PyArray_CanCastTypeTo(PyArray_DESCR(self),
PyArray_DESCR(array_other),
NPY_EQUIV_CASTING);
if (_res == 0) {
/* 2015-05-07, 1.10 */
Py_DECREF(array_other);
if (DEPRECATE_FUTUREWARNING(
"elementwise == comparison failed and returning scalar "
"instead; this will raise an error or perform "
"elementwise comparison in the future.") < 0) {
return NULL;
}
Py_INCREF(Py_False);
return Py_False;
}

On NumPy 1.20, the output is correct:

array([ True,  True,  True])

Or conversely, if we use a non-zero length void dtype, e.g.,

>>> x = np.array([b'foo', b'bar'], np.void)
>>> x == x
array([ True,  True])

CC @seberg since this smells similar to #19085

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions