@@ -92,7 +92,7 @@ def merge(
92
92
93
93
94
94
def _groupby_and_merge (
95
- by , on , left , right , _merge_pieces , check_duplicates : bool = True
95
+ by , on , left , right : "DataFrame" , _merge_pieces , check_duplicates : bool = True
96
96
):
97
97
"""
98
98
groupby & merge; we are always performing a left-by type operation
@@ -313,7 +313,7 @@ def merge_asof(
313
313
suffixes = ("_x" , "_y" ),
314
314
tolerance = None ,
315
315
allow_exact_matches : bool = True ,
316
- direction = "backward" ,
316
+ direction : str = "backward" ,
317
317
):
318
318
"""
319
319
Perform an asof merge. This is similar to a left-join except that we
@@ -1299,19 +1299,21 @@ def _get_join_indexers(
1299
1299
right_keys
1300
1300
), "left_key and right_keys must be the same length"
1301
1301
1302
- # bind `sort` arg. of _factorize_keys
1303
- fkeys = partial (_factorize_keys , sort = sort )
1304
-
1305
1302
# get left & right join labels and num. of levels at each location
1306
- llab , rlab , shape = map (list , zip (* map (fkeys , left_keys , right_keys )))
1303
+ mapped = (
1304
+ _factorize_keys (left_keys [n ], right_keys [n ], sort = sort )
1305
+ for n in range (len (left_keys ))
1306
+ )
1307
+ zipped = zip (* mapped )
1308
+ llab , rlab , shape = [list (x ) for x in zipped ]
1307
1309
1308
1310
# get flat i8 keys from label lists
1309
1311
lkey , rkey = _get_join_keys (llab , rlab , shape , sort )
1310
1312
1311
1313
# factorize keys to a dense i8 space
1312
1314
# `count` is the num. of unique keys
1313
1315
# set(lkey) | set(rkey) == range(count)
1314
- lkey , rkey , count = fkeys (lkey , rkey )
1316
+ lkey , rkey , count = _factorize_keys (lkey , rkey , sort = sort )
1315
1317
1316
1318
# preserve left frame order if how == 'left' and sort == False
1317
1319
kwargs = copy .copy (kwargs )
@@ -1487,12 +1489,12 @@ def get_result(self):
1487
1489
return result
1488
1490
1489
1491
1490
- def _asof_function (direction ):
1492
+ def _asof_function (direction : str ):
1491
1493
name = "asof_join_{dir}" .format (dir = direction )
1492
1494
return getattr (libjoin , name , None )
1493
1495
1494
1496
1495
- def _asof_by_function (direction ):
1497
+ def _asof_by_function (direction : str ):
1496
1498
name = "asof_join_{dir}_on_X_by_Y" .format (dir = direction )
1497
1499
return getattr (libjoin , name , None )
1498
1500
@@ -1536,7 +1538,7 @@ def __init__(
1536
1538
how : str = "asof" ,
1537
1539
tolerance = None ,
1538
1540
allow_exact_matches : bool = True ,
1539
- direction = "backward" ,
1541
+ direction : str = "backward" ,
1540
1542
):
1541
1543
1542
1544
self .by = by
@@ -1775,11 +1777,11 @@ def flip(xs):
1775
1777
1776
1778
def _get_multiindex_indexer (join_keys , index : MultiIndex , sort : bool ):
1777
1779
1778
- # bind `sort` argument
1779
- fkeys = partial (_factorize_keys , sort = sort )
1780
-
1781
1780
# left & right join labels and num. of levels at each location
1782
- mapped = (fkeys (index .levels [n ], join_keys [n ]) for n in range (len (index .levels )))
1781
+ mapped = (
1782
+ _factorize_keys (index .levels [n ], join_keys [n ], sort = sort )
1783
+ for n in range (index .nlevels )
1784
+ )
1783
1785
zipped = zip (* mapped )
1784
1786
rcodes , lcodes , shape = [list (x ) for x in zipped ]
1785
1787
if sort :
@@ -1804,7 +1806,7 @@ def _get_multiindex_indexer(join_keys, index: MultiIndex, sort: bool):
1804
1806
lkey , rkey = _get_join_keys (lcodes , rcodes , shape , sort )
1805
1807
1806
1808
# factorize keys to a dense i8 space
1807
- lkey , rkey , count = fkeys (lkey , rkey )
1809
+ lkey , rkey , count = _factorize_keys (lkey , rkey , sort = sort )
1808
1810
1809
1811
return libjoin .left_outer_join (lkey , rkey , count , sort = sort )
1810
1812
0 commit comments