-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
pandas.Series.__eq__ is broken for series with different index #1134
Comments
This is actually a feature / deliberate choice and not a bug-- it's related to #652. Back in January I changed the comparison methods to do auto-alignment, but found that it led to a large amount of bugs / breakage for users and, in particular, many NumPy functions (which regularly do things like This gets back to the issue that Series isn't quite ndarray-like enough and should probably not be a subclass of ndarray. So, I haven't got a good answer for you except for that; auto-alignment would be ideal but I don't think I can do it unless I make Series not a subclass of ndarray. I think this is probably a good idea but not likely to happen until 0.9 or 0.10 (several months down the road). |
Interesting, thanks for the answer. Is Out of interest, is there a way to figure out whether s1 and s2 are a view on the same underlying series and in this case have Not sure whether you would want to do that even if it was possible, e.g. |
Interesting, that would be a hack around the |
closing as not a bug |
@jreback I was answering this SO question: http://stackoverflow.com/questions/22983523/comparing-pandas-series-for-equality-when-they-are-in-different-orders/22983621#22983621. And I was wondering: I understand that
|
@jorisvandenbossche interesting, let's reopen and i'll take a look |
+1 for @jorisvandenbossche's suggestion of at least making the .eq, .ne, .lt, .le, .gt, .ge methods flexible, i.e. use alignment. |
From what I am reading above, it sounds like a fix might be more complicated/a while off. Could we in the meantime add something to the documentation about this? I discovered this issue for myself recently and it took me a long time to figure out what was going on. At some point I did check the documentation to see if my understanding of index alignment was correct and there was no mention there that this only applies to the +, -, *, / operators and not to ==, !=, <, <=, >, >=. In particular,
|
see #6860 its not that 'hard' the fix at all. Though I think that doing JUST for (I think the docs really mean |
Also came up here: http://stackoverflow.com/q/25435229/1240268 (update: oh, maybe thats with comparison) |
Bumping this issue |
+1 on adding flexible methods. Also, there are inconsistencies in normal ops between SeriesArithmeticaligns with labels.
Comparisonignores labels, raises when lengths are different.
Boolean (logical)ignores labels, ignores length mismatch.
DataFrameArithmeticaligns with labels.
Comparisonraises when labels are different.
Boolean (logical)aligns with labels.
Based on above, I think followings are consistent:
If OK, I'd like to do 2 changes:
|
Something seems to be wrong with s1 == s2 when s1 and s2 don't have the same index. Here is a snippet example:
with the output:
On the other hand using combine works fine:
I guess you can first align s1 and s2 and then compare them, but is there a good reason why this couldn't work out of the box?
There doesn't seem to be any tests for pandas.Series. eq for two series with a different index in pandas/pandas/tests/test_series.py. I have a patch lying around to add such a test and I could commit it if that's useful.
The text was updated successfully, but these errors were encountered: