@@ -2325,13 +2325,15 @@ def _apply_binop(
2325
2325
2326
2326
return self .project_exprs (exprs , labels = labels , drop = True )
2327
2327
2328
+ # TODO: Re-implement join in terms of merge (requires also adding remaining merge args)
2328
2329
def join (
2329
2330
self ,
2330
2331
other : Block ,
2331
2332
* ,
2332
2333
how = "left" ,
2333
2334
sort : bool = False ,
2334
2335
block_identity_join : bool = False ,
2336
+ always_order : bool = False ,
2335
2337
) -> Tuple [Block , Tuple [Mapping [str , str ], Mapping [str , str ]],]:
2336
2338
"""
2337
2339
Join two blocks objects together, and provide mappings between source columns and output columns.
@@ -2345,6 +2347,8 @@ def join(
2345
2347
if true will sort result by index
2346
2348
block_identity_join (bool):
2347
2349
If true, will not convert join to a projection (implicitly assuming unique indices)
2350
+ always_order (bool):
2351
+ If true, will always preserve input ordering, even if ordering mode is partial
2348
2352
2349
2353
Returns:
2350
2354
Block, (left_mapping, right_mapping): Result block and mappers from input column ids to result column ids.
@@ -2390,10 +2394,14 @@ def join(
2390
2394
self ._throw_if_null_index ("join" )
2391
2395
other ._throw_if_null_index ("join" )
2392
2396
if self .index .nlevels == other .index .nlevels == 1 :
2393
- return join_mono_indexed (self , other , how = how , sort = sort )
2397
+ return join_mono_indexed (
2398
+ self , other , how = how , sort = sort , propogate_order = always_order
2399
+ )
2394
2400
else : # Handles cases where one or both sides are multi-indexed
2395
2401
# Always sort mult-index join
2396
- return join_multi_indexed (self , other , how = how , sort = sort )
2402
+ return join_multi_indexed (
2403
+ self , other , how = how , sort = sort , propogate_order = always_order
2404
+ )
2397
2405
2398
2406
def is_monotonic_increasing (
2399
2407
self , column_id : typing .Union [str , Sequence [str ]]
@@ -2850,7 +2858,8 @@ def join_mono_indexed(
2850
2858
right : Block ,
2851
2859
* ,
2852
2860
how = "left" ,
2853
- sort = False ,
2861
+ sort : bool = False ,
2862
+ propogate_order : bool = False ,
2854
2863
) -> Tuple [Block , Tuple [Mapping [str , str ], Mapping [str , str ]],]:
2855
2864
left_expr = left .expr
2856
2865
right_expr = right .expr
@@ -2861,6 +2870,7 @@ def join_mono_indexed(
2861
2870
conditions = (
2862
2871
join_defs .JoinCondition (left .index_columns [0 ], right .index_columns [0 ]),
2863
2872
),
2873
+ propogate_order = propogate_order ,
2864
2874
)
2865
2875
2866
2876
left_index = get_column_left [left .index_columns [0 ]]
@@ -2895,7 +2905,8 @@ def join_multi_indexed(
2895
2905
right : Block ,
2896
2906
* ,
2897
2907
how = "left" ,
2898
- sort = False ,
2908
+ sort : bool = False ,
2909
+ propogate_order : bool = False ,
2899
2910
) -> Tuple [Block , Tuple [Mapping [str , str ], Mapping [str , str ]],]:
2900
2911
if not (left .index .is_uniquely_named () and right .index .is_uniquely_named ()):
2901
2912
raise ValueError ("Joins not supported on indices with non-unique level names" )
@@ -2924,6 +2935,7 @@ def join_multi_indexed(
2924
2935
join_defs .JoinCondition (left , right )
2925
2936
for left , right in zip (left_join_ids , right_join_ids )
2926
2937
),
2938
+ propogate_order = propogate_order ,
2927
2939
)
2928
2940
2929
2941
left_ids_post_join = [get_column_left [id ] for id in left_join_ids ]
0 commit comments