-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: Discrepency between documentation and output for outer merge on index when left and right indices match and are unique #55992
Comments
cc @lukemanley if interested in following up here |
So this behavior exists in
I agree it feels inconsistent and its also annoying that merging on columns vs indexes produces a different default sort behavior in this case. @mroeschke - do you think the exising behavior should be documented do you think outer joins/merges should sort by default regardless of whether the indexes are equal? |
That behaviour is handled by special-case code in
And in any case does obey
Personally, I think adding another carve-out in the documentation for outer joins is the wrong approach (as is having carve-outs in Moreover, this adds to the cognitive load when using the library since there are no simple patterns. |
I think for these merge case we should follow the current merge documentation and sort the keys lexicographically. The |
See discussion in #25007, #24959, and linked issues/PRs. If I read through, the Index setops seem to have originally (almost accidentally) gained a |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Since #54611, merging dataframes produces a result that almost always matches the documented behaviour. The only exception appears to be an
outer
merge on an index when the left and right indexes are equal and unique. In this case, irrespective ofsort=True/False
, the returned result has the order of the input index.Expected Behavior
Since there isn't a carve-out in the documentation for this specific corner-case, I would expect that
pd.merge(..., how="outer")
always sorts the output lexicographically according to the join key(s).Installed Versions
The text was updated successfully, but these errors were encountered: