Comparison changes

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Comparison changes

Sebastian Berg
Hi all,

in https://github.com/numpy/numpy/pull/3514 I proposed some changes to
the comparison operators. This includes:

1. Comparison with None will broadcast in the future, so that `arr ==
None` will actually compare all elements to None. (A FutureWarning for
now)

2. I added that == and != will give FutureWarning when an error was
raised. In the future they should not silence these errors anymore. (For
example shape mismatches)

3. We used to use PyObject_RichCompareBool for equality which includes
an identity check. I propose to not do that identity check since we have
elementwise equality (returning an object array for objects would be
nice in some ways, but I think that is only an option for a dedicated
function). The reason is that for example

>>> a = np.array([np.array([1, 2, 3]), 1])
>>> b = np.array([np.array([1, 2, 3]), 1])
>>> a == b

will happen to work if it happens to be that `a[0] is b[0]`. This
currently has no deprecation, since the logic is in the inner loop and I
am not sure if it is easy to add well there.

Are there objections/comments to these changes?

Regards,

Sebastian

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Comparison changes

Nathaniel Smith

On 25 Jan 2014 00:05, "Sebastian Berg" <[hidden email]> wrote:
>
> Hi all,
>
> in https://github.com/numpy/numpy/pull/3514 I proposed some changes to
> the comparison operators. This includes:
>
> 1. Comparison with None will broadcast in the future, so that `arr ==
> None` will actually compare all elements to None. (A FutureWarning for
> now)
>
> 2. I added that == and != will give FutureWarning when an error was
> raised. In the future they should not silence these errors anymore. (For
> example shape mismatches)

This can just be a DeprecationWarning, because the only change is to raise new more errors.

> 3. We used to use PyObject_RichCompareBool for equality which includes
> an identity check. I propose to not do that identity check since we have
> elementwise equality (returning an object array for objects would be
> nice in some ways, but I think that is only an option for a dedicated
> function). The reason is that for example
>
> >>> a = np.array([np.array([1, 2, 3]), 1])
> >>> b = np.array([np.array([1, 2, 3]), 1])
> >>> a == b
>
> will happen to work if it happens to be that `a[0] is b[0]`. This
> currently has no deprecation, since the logic is in the inner loop and I
> am not sure if it is easy to add well there.

Surely any environment where we can call PyObject_RichCompareBool is an environment where we can issue a warning...?

-n


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Comparison changes

Sebastian Berg
On Sat, 2014-01-25 at 00:18 +0000, Nathaniel Smith wrote:

> On 25 Jan 2014 00:05, "Sebastian Berg" <[hidden email]>
> wrote:
> >
> > Hi all,
> >
> > in https://github.com/numpy/numpy/pull/3514 I proposed some changes
> to
> > the comparison operators. This includes:
> >
> > 1. Comparison with None will broadcast in the future, so that `arr
> ==
> > None` will actually compare all elements to None. (A FutureWarning
> for
> > now)
> >
> > 2. I added that == and != will give FutureWarning when an error was
> > raised. In the future they should not silence these errors anymore.
> (For
> > example shape mismatches)
>
> This can just be a DeprecationWarning, because the only change is to
> raise new more errors.
>
Right, already is the case.

> > 3. We used to use PyObject_RichCompareBool for equality which
> includes
> > an identity check. I propose to not do that identity check since we
> have
> > elementwise equality (returning an object array for objects would be
> > nice in some ways, but I think that is only an option for a
> dedicated
> > function). The reason is that for example
> >
> > >>> a = np.array([np.array([1, 2, 3]), 1])
> > >>> b = np.array([np.array([1, 2, 3]), 1])
> > >>> a == b
> >
> > will happen to work if it happens to be that `a[0] is b[0]`. This
> > currently has no deprecation, since the logic is in the inner loop
> and I
> > am not sure if it is easy to add well there.
>
> Surely any environment where we can call PyObject_RichCompareBool is
> an environment where we can issue a warning...?
>
Right, I suppose an extra identity check and comparing it with the other
result is indeed no problem. So I think I will add that.

- Sebastian


> -n
>
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/numpy-discussion


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Comparison changes

Stéfan van der Walt
In reply to this post by Sebastian Berg
On Sat, 25 Jan 2014 01:05:15 +0100, Sebastian Berg wrote:
> 1. Comparison with None will broadcast in the future, so that `arr ==
> None` will actually compare all elements to None. (A FutureWarning for
> now)

This is a very useful change in behavior--thanks!

Stéfan

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/numpy-discussion