Skip to content

BUG: right merge not preserve row order (#27453) #27762

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

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename vars and add comment for clarity
  • Loading branch information
Nico Cernek committed Jan 1, 2020
commit 7fc644174583c67d09bd52d100732240a124c028
8 changes: 5 additions & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1319,17 +1319,19 @@ def _get_join_indexers(
# `count` is the num. of unique keys
# set(lkey) | set(rkey) == range(count)

# flip left and right keys if performing a right merge
# to preserve right merge row order (GH 27453)
if how == "right":
rkey, lkey, count = fkeys(rkey, lkey)
factorized_rkey, factorized_lkey, count = fkeys(rkey, lkey)
else:
lkey, rkey, count = fkeys(lkey, rkey)
factorized_lkey, factorized_rkey, count = fkeys(lkey, rkey)
# preserve left frame order if how == 'left' and sort == False
kwargs = copy.copy(kwargs)
if how == "left":
kwargs["sort"] = sort
join_func = _join_functions[how]

return join_func(lkey, rkey, count, **kwargs)
return join_func(factorized_lkey, factorized_rkey, count, **kwargs)


def _restore_dropped_levels_multijoin(
Expand Down