Skip to content

Commit 7b268c4

Browse files
author
Nico Cernek
committed
revert commit ed54bec
1 parent 21a2268 commit 7b268c4

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

pandas/core/reshape/merge.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,41 +1275,32 @@ def _get_join_indexers(left_keys, right_keys, sort=False, how="inner", **kwargs)
12751275
indexers into the left_keys, right_keys
12761276
12771277
"""
1278-
_how = how
1279-
if how == "right":
1280-
left_keys, right_keys = right_keys, left_keys
1281-
_how = "left"
1282-
12831278
assert len(left_keys) == len(
12841279
right_keys
12851280
), "left_key and right_keys must be the same length"
12861281

12871282
# bind `sort` arg. of _factorize_keys
12881283
fkeys = partial(_factorize_keys, sort=sort)
1289-
12901284
# get left & right join labels and num. of levels at each location
12911285
llab, rlab, shape = map(list, zip(*map(fkeys, left_keys, right_keys)))
12921286

12931287
# get flat i8 keys from label lists
1288+
print(llab, rlab)
12941289
lkey, rkey = _get_join_keys(llab, rlab, shape, sort)
12951290

12961291
# factorize keys to a dense i8 space
12971292
# `count` is the num. of unique keys
12981293
# set(lkey) | set(rkey) == range(count)
1299-
lkey, rkey, count = fkeys(lkey, rkey)
13001294

1295+
print(lkey, rkey)
1296+
lkey, rkey, count = fkeys(lkey, rkey)
13011297
# preserve left frame order if how == 'left' and sort == False
13021298
kwargs = copy.copy(kwargs)
1303-
if _how == "left":
1299+
if how == "left":
13041300
kwargs["sort"] = sort
1305-
join_func = _join_functions[_how]
1306-
1307-
left_indexer, right_indexer = join_func(lkey, rkey, count, **kwargs)
1308-
1309-
if how == "right":
1310-
left_indexer, right_indexer = right_indexer, left_indexer
1301+
join_func = _join_functions[how]
13111302

1312-
return left_indexer, right_indexer
1303+
return join_func(lkey, rkey, count, **kwargs)
13131304

13141305

13151306
def _restore_dropped_levels_multijoin(
@@ -1830,9 +1821,29 @@ def _left_join_on_index(left_ax, right_ax, join_keys, sort=False):
18301821
return left_ax, None, right_indexer
18311822

18321823

1824+
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
1841+
1842+
18331843
_join_functions = {
18341844
"inner": libjoin.inner_join,
18351845
"left": libjoin.left_outer_join,
1846+
"right": _right_outer_join,
18361847
"outer": libjoin.full_outer_join,
18371848
}
18381849

0 commit comments

Comments
 (0)