Skip to content
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

API: ops alignment behavior inconsistencies #28759

Closed
jbrockmendel opened this issue Oct 2, 2019 · 4 comments
Closed

API: ops alignment behavior inconsistencies #28759

jbrockmendel opened this issue Oct 2, 2019 · 4 comments
Labels
API - Consistency Internal Consistency of API/Behavior Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@jbrockmendel
Copy link
Member

In both Series and DataFrame ops, we have inconsistent behavior for when we call self.align vs when we raise. Everything discussed here is for non-flex ops.

Case 1: consider op(ser1, ser2) for two Series with non-matching indexes.

  • arithmetic ops call self.align(other)
  • comparison ops raise ValueError("Can only compare identically-labeled Series objects")
  • logical ops call self.align(other)

Case 2: consider op(df1, df2) for two DataFrames with non-matching axes

  • arithmetic ops call self.align(other)
  • comparison ops raise ValueError("Can only compare identically-labeled DataFrame objects")
  • logical ops call self.align(other)

Case 3) consider op(df, ser). This always aligns, with comparison not being treated differently from the other two.

The policy (and code) would be simpler if we changed this so that either:
a) the comparison op in case 3 doesn't align, matching cases 1 and 2
b) comparison ops always align, matching arithmetic and logical ops

@jorisvandenbossche
Copy link
Member

The (non-)alignment of comparison ops (for the first two cases) is something we discussed long time ago, I recall, and was at that time decided consciously. To be clear: not saying that it is therefore the best behaviour, just meaning it is not an accidental, historical inconsistency, as far as I recall. So worth digging up the reasoning (will try to look for relevant issues later).

@jbrockmendel
Copy link
Member Author

@jorisvandenbossche thanks. As long as its intentional, its fine by me. If you do stumble on the old thread, pls LMK and I'll add a comment in the code pointing back to it for the next time I forget.

@jreback
Copy link
Contributor

jreback commented Oct 6, 2019

actually i would like to see case 3)’have the non-align for comparisons (raise)
for consistency

@jbrockmendel jbrockmendel reopened this Oct 6, 2019
@jbrockmendel jbrockmendel added the Numeric Operations Arithmetic, Comparison, and Logical operations label Oct 16, 2019
@jbrockmendel jbrockmendel added the API - Consistency Internal Consistency of API/Behavior label Sep 21, 2020
@jorisvandenbossche
Copy link
Member

So #36795 fixed the inconsistency for df/ser comparisons compared to the others. Shall we close this then?
Otherwise, if someone further wants to look at changing the inconsistency between arithmetic and comparison ops, you will need to dig up the old discussions about this to find out the reasoning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

No branches or pull requests

3 participants