Skip to content

NumPy should warn (eventually raise an error?) on comparisons between complex numbers #15981

@shoyer

Description

@shoyer

Python (version 3, at least) raises an error, but NumPy uses lexicographic order (see #11505 for discussion).

We should clean this up to match Python. This behavior is fine for sorting, but I don't think it makes sense for comparisons between numbers. I think most comparisons between complex numbers are probably latent bugs (as was the case where I discovered this).

My suggestion would be to start by issuing a DeprecationWarning, and then maybe make it a true error at some point in the distance future.

Reproducing code example:

>>> x = 1 + 1j
>>> y = 2 + 1j
>>> x < y
TypeError: '<' not supported between instances of 'complex' and 'complex'
>>> np.array(x) < np.array(y)
True

Numpy/Python version information:

1.18.2 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0]

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