Skip to content

Commit 0ad9884

Browse files
author
Nico Cernek
committed
change logic to swap left and right if how==right
1 parent b86d474 commit 0ad9884

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

pandas/core/reshape/merge.py

+6-19
Original file line numberDiff line numberDiff line change
@@ -1286,15 +1286,16 @@ def _get_join_indexers(left_keys, right_keys, sort=False, how="inner", **kwargs)
12861286
llab, rlab, shape = map(list, zip(*map(fkeys, left_keys, right_keys)))
12871287

12881288
# get flat i8 keys from label lists
1289-
print(llab, rlab)
12901289
lkey, rkey = _get_join_keys(llab, rlab, shape, sort)
12911290

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

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

18241825

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

18431830

18441831
_join_functions = {

0 commit comments

Comments
 (0)