pydata/pandas — pull request #8948 by behzadnouri (2014-11-30 22:20:32+00:00)
Title: BUG: preserve left frame order in left merge

closes https://github.com/pydata/pandas/issues/7331

on master:

>>> left
dates states
0 20140101 CA
1 20140102 NY
2 20140103 CA
>>> right
stateid states
0 1 CA
1 2 NY
>>> pd.merge(left, right, how='left', on='states', sort=False)
dates states stateid
0 20140101 CA 1
1 20140103 CA 1
2 20140102 NY 2
`DataFrame.join` already works fine:

>>> left.join(right.set_index('states'), on='states', how='left')
dates states stateid
0 20140101 CA 1
1 20140102 NY 2
2 20140103 CA 1

on branch:

>>> pd.merge(left, right, how='left', on='states', sort=False)
dates states stateid
0 20140101 CA 1
1 20140102 NY 2
2 20140103 CA 1

>>> pd.merge(left, right, how='left', on='states', sort=True)
dates states stateid
0 20140101 CA 1
1 20140103 CA 1
2 20140102 NY 2