Skip to content

Commit 4c932c0

Browse files
author
Nico Cernek
committed
change logic to swap left and right if how==right
1 parent 7b268c4 commit 4c932c0

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

pandas/core/reshape/merge.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,15 +1285,16 @@ def _get_join_indexers(left_keys, right_keys, sort=False, how="inner", **kwargs)
12851285
llab, rlab, shape = map(list, zip(*map(fkeys, left_keys, right_keys)))
12861286

12871287
# get flat i8 keys from label lists
1288-
print(llab, rlab)
12891288
lkey, rkey = _get_join_keys(llab, rlab, shape, sort)
12901289

12911290
# factorize keys to a dense i8 space
12921291
# `count` is the num. of unique keys
12931292
# set(lkey) | set(rkey) == range(count)
12941293

1295-
print(lkey, rkey)
1296-
lkey, rkey, count = fkeys(lkey, rkey)
1294+
if how == "right":
1295+
rkey, lkey, count = fkeys(rkey, lkey)
1296+
else:
1297+
lkey, rkey, count = fkeys(lkey, rkey)
12971298
# preserve left frame order if how == 'left' and sort == False
12981299
kwargs = copy.copy(kwargs)
12991300
if how == "left":
@@ -1822,22 +1823,8 @@ def _left_join_on_index(left_ax, right_ax, join_keys, sort=False):
18221823

18231824

18241825
def _right_outer_join(x, y, max_groups):
1825-
new_x = []
1826-
for i in y:
1827-
if i in x:
1828-
new_x.append(i)
1829-
else:
1830-
new_x.append(-1)
1831-
1832-
return np.array(new_x), np.array([0, 1, 2])
1833-
# right_indexer, left_indexer = libjoin.left_outer_join(y, x, max_groups)
1834-
# print('right_index: ', y, " - ", right_indexer)
1835-
# print('left_index: ', x, " - ", left_indexer)
1836-
1837-
# assert np.array_equal(left_indexer, np.array([1, 2, -1]))
1838-
# assert np.array_equal(right_indexer, np.array([1, 2, 0]))
1839-
# return np.array([-1, 1, 2]), np.array([0,1,2])
1840-
# return left_indexer, right_indexer
1826+
right_indexer, left_indexer = libjoin.left_outer_join(y, x, max_groups)
1827+
return left_indexer, right_indexer
18411828

18421829

18431830
_join_functions = {

0 commit comments

Comments
 (0)