[Numpy-discussion] Allow == and != to raise errors
ben.root at ou.edu
Fri Jul 12 09:13:51 EDT 2013
I can see where you are getting at, but I would have to disagree. First of
all, when a comparison between two mis-shaped arrays occur, you get back a
bone fide python boolean, not a numpy array of bools. So if any action was
taken on the result of such a comparison assumed that the result was some
sort of an array, it would fail (yes, this does make it a bit difficult to
trace back the source of the problem, but not impossible).
Second, no semantics are broken with this. Are the arrays equal or not? If
they weren't broadcastible, then returning False for == and True for !=
makes perfect sense to me. At least, that is my take on it.
On Fri, Jul 12, 2013 at 8:38 AM, Sebastian Berg
<sebastian at sipsolutions.net>wrote:
> 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 : np.array([1,2,3]) == np.array([1,2])
> Out: False
> In : np.array([1, np.array([2, 3])], dtype=object) == [1, 2]
> Out: 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)
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion