-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DISCUSS: Should object array comparisons return objects? (Trac #2117) #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@charris wrote on 2012-04-27 Strange indeed. This is going to be fun to figure out. My guess it that the first item is the same object in a and a.copy(), whereas it is a different object for the other array created with the same parameters... and it is so.
So the comparison is comparing object pointers rather than calling a comparison routine. It's certainly easier to compare the pointers. I'm not sure if this is a bug or a feature ;) Shouldn't be hard to find where it happens. |
@charris wrote on 2012-04-27 OTOH
So it looks specific to arrays. |
This looks weird on first sight but it is actually down to python's C-API. My guess is that If that is considered the right approach, I will do a small PR to that effect (for both things). |
Actually, maybe the current behaviour should just be kept, since even if its somewhat wrong it is also what python lists do... |
In principle I guess But! What I want to know is, why does that last comparison return a scalar?!
Surely that should be |
@njsmith agreed, it would logically not cast to bool I guess. The last thing is a bug in numpy if you check |
This should be about as close to being fixed as it can be, so closing (no "is" check anymore, and |
hm @seberg , so now it just consistently provides incorrect answer? >>> import numpy as np
>>> print np.__version__
1.14.0.dev0+14cd918
>>> a = np.array([np.array([0, 1]), np.array(1)])
>>> print a.dtype
object
>>> print a == a.copy()
False
>>> print a == np.array([np.array([0, 1]), np.array(1)])
False why it should be the correct behavior whenever objects are comparable etc? Edit: (mattip, 2019-10-28) formatting |
No:
|
@yarikoptic hmmm, or maybe I am missing something. What do you expect? Then again, maybe we planned to go via an error to go somewhere else. Apparently we still do the cast to bool (which for arrays will typically create an error), so that we would only go to error for now. |
Heh, I don't remember, I am sure there are other issues about this transition, but if you feel better, will reopen it :). |
I am not sure why I do not see those deprecation warnings and you do (I cut pasted exact command and output with the version as currently straight from the I expect that a "thing" should be equal to its own copy, either element-wise (custom numpy semantic) or just altogether (result of |
@yarikoptic unfortunately deprecation warning are only printed if you endable them to be (most users don't care much, EDIT: This is a python choice, not ours), we likely will need to turn these into a VisibleDeprecationWarning before actually changing things :(. Well, the current state fixes if you have an object array with e.g. The code currently always casts to bool, and |
Raising this again as those deprecation warnings have expired and it is time to clean up the code. The question is this: given an object array A trickier one: a = np.array([1, [1, 2, 3]], dtype=object); a == 0 |
I feel the main options are the options are:
The first one is what we made all the fuzz about. The second is probable the easier sell/better. So I am tending towards it. The tricky thing is that our warnings warn about the first one right now (indirectly, but nevertheless)?! You are right, the last example will stump users, but it is the consistent choice and trying to be smart would just get us in trouble. |
@seberg's option 2 seems like the correct approach.
|
It is an interesting question whether we should maybe just reorder the whole loop priority to use EDIT: Just to be clear, that should solve the whole |
So... this issue is now resolved towards option "1." above. We still use the I honestly think that is OK to enforce a boolean result for array comparison, but of course we could default to the object result. The way it is now, you would have to use |
I.e. the behavior is consistent now, I think. The only remaining issue is to discuss whether we want to modify the behavior of object comparisons in general. |
Let's close this. If the current behavior does not match someone's expectations in a concrete use case, please open a new issue. |
Uh oh!
There was an error while loading. Please reload this page.
Original ticket http://projects.scipy.org/numpy/ticket/2117 on 2012-04-26 by @yarikoptic, assigned to unknown.
This issue became more visible since 1.6.x allowed to construct such heterogeneous arrays without specification of dtype=object:
So -- comparing an object array to itself's copy worked just fine but comparison to identically created another one -- failed.
Edit: (mattip, 2019-10-28) formatting
The text was updated successfully, but these errors were encountered: