[Numpy-discussion] Allow == and != to raise errors

Sebastian Berg sebastian at sipsolutions.net
Fri Jul 12 08:38:08 EDT 2013


the array comparisons == and != never raise errors but instead simply
return False for invalid comparisons.

The main example are arrays of non-matching dimensions, and object
arrays with invalid element-wise comparisons:

In [1]: np.array([1,2,3]) == np.array([1,2])
Out[1]: False

In [2]: np.array([1, np.array([2, 3])], dtype=object) == [1, 2]
Out[2]: False

This seems wrong to me, and I am sure not just me. I doubt any large
projects makes use of such comparisons and assume that most would prefer
the shape mismatch to raise an error, so I would like to change it. But
I am a bit unsure especially about smaller projects. So to keep the
transition a bit safer could imagine implementing a FutureWarning for
these cases (and that would at least notify new users that what they are
doing doesn't seem like the right thing).

So the question is: Is such a change safe enough, or is there some good
reason for the current behavior that I am missing?



(There may be other issues with structured types that would continue
returning False I think, because neither side knows how to compare)

More information about the NumPy-Discussion mailing list