Skip to content

Commit a8954fe

Browse files
author
Nico Cernek
committed
revert commit ed54bec
1 parent de44eae commit a8954fe

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
@@ -1297,18 +1297,12 @@ def _get_join_indexers(
12971297
indexers into the left_keys, right_keys
12981298
12991299
"""
1300-
_how = how
1301-
if how == "right":
1302-
left_keys, right_keys = right_keys, left_keys
1303-
_how = "left"
1304-
13051300
assert len(left_keys) == len(
13061301
right_keys
13071302
), "left_key and right_keys must be the same length"
13081303

13091304
# bind `sort` arg. of _factorize_keys
13101305
fkeys = partial(_factorize_keys, sort=sort)
1311-
13121306
# get left & right join labels and num. of levels at each location
13131307
mapped = (
13141308
_factorize_keys(left_keys[n], right_keys[n], sort=sort)
@@ -1318,25 +1312,22 @@ def _get_join_indexers(
13181312
llab, rlab, shape = [list(x) for x in zipped]
13191313

13201314
# get flat i8 keys from label lists
1315+
print(llab, rlab)
13211316
lkey, rkey = _get_join_keys(llab, rlab, shape, sort)
13221317

13231318
# factorize keys to a dense i8 space
13241319
# `count` is the num. of unique keys
13251320
# set(lkey) | set(rkey) == range(count)
1326-
lkey, rkey, count = fkeys(lkey, rkey)
13271321

1322+
print(lkey, rkey)
1323+
lkey, rkey, count = fkeys(lkey, rkey)
13281324
# preserve left frame order if how == 'left' and sort == False
13291325
kwargs = copy.copy(kwargs)
1330-
if _how == "left":
1326+
if how == "left":
13311327
kwargs["sort"] = sort
1332-
join_func = _join_functions[_how]
1333-
1334-
left_indexer, right_indexer = join_func(lkey, rkey, count, **kwargs)
1335-
1336-
if how == "right":
1337-
left_indexer, right_indexer = right_indexer, left_indexer
1328+
join_func = _join_functions[how]
13381329

1339-
return left_indexer, right_indexer
1330+
return join_func(lkey, rkey, count, **kwargs)
13401331

13411332

13421333
def _restore_dropped_levels_multijoin(
@@ -1865,9 +1856,29 @@ def _left_join_on_index(left_ax: Index, right_ax: Index, join_keys, sort: bool =
18651856
return left_ax, None, right_indexer
18661857

18671858

1859+
def _right_outer_join(x, y, max_groups):
1860+
new_x = []
1861+
for i in y:
1862+
if i in x:
1863+
new_x.append(i)
1864+
else:
1865+
new_x.append(-1)
1866+
1867+
return np.array(new_x), np.array([0, 1, 2])
1868+
# right_indexer, left_indexer = libjoin.left_outer_join(y, x, max_groups)
1869+
# print('right_index: ', y, " - ", right_indexer)
1870+
# print('left_index: ', x, " - ", left_indexer)
1871+
1872+
# assert np.array_equal(left_indexer, np.array([1, 2, -1]))
1873+
# assert np.array_equal(right_indexer, np.array([1, 2, 0]))
1874+
# return np.array([-1, 1, 2]), np.array([0,1,2])
1875+
# return left_indexer, right_indexer
1876+
1877+
18681878
_join_functions = {
18691879
"inner": libjoin.inner_join,
18701880
"left": libjoin.left_outer_join,
1881+
"right": _right_outer_join,
18711882
"outer": libjoin.full_outer_join,
18721883
}
18731884

0 commit comments

Comments
 (0)