@@ -296,12 +296,16 @@ def test_single_condition_less_than_floats_keep_first(df, right):
296
296
allow_exact_matches = False ,
297
297
)
298
298
expected .index = range (len (expected ))
299
- actual = df [["B" ]].conditional_join (
300
- right [["Numeric" ]].sort_values ("Numeric" ),
301
- ("B" , "Numeric" , "<" ),
302
- how = "left" ,
303
- sort_by_appearance = False ,
304
- keep = "first" ,
299
+ actual = (
300
+ df [["B" ]]
301
+ .conditional_join (
302
+ right [["Numeric" ]].sort_values ("Numeric" ),
303
+ ("B" , "Numeric" , "<" ),
304
+ how = "left" ,
305
+ sort_by_appearance = False ,
306
+ keep = "first" ,
307
+ )
308
+ .sort_values (["B" , "Numeric" ], ignore_index = True )
305
309
)
306
310
307
311
assert_frame_equal (expected , actual )
@@ -324,12 +328,16 @@ def test_single_condition_less_than_floats_keep_last(df, right):
324
328
allow_exact_matches = False ,
325
329
)
326
330
expected .index = range (len (expected ))
327
- actual = df [["B" ]].conditional_join (
328
- right [["Numeric" ]],
329
- ("B" , "Numeric" , ">" ),
330
- how = "left" ,
331
- sort_by_appearance = False ,
332
- keep = "last" ,
331
+ actual = (
332
+ df [["B" ]]
333
+ .conditional_join (
334
+ right [["Numeric" ]],
335
+ ("B" , "Numeric" , ">" ),
336
+ how = "left" ,
337
+ sort_by_appearance = False ,
338
+ keep = "last" ,
339
+ )
340
+ .sort_values (["B" , "Numeric" ], ignore_index = True )
333
341
)
334
342
335
343
assert_frame_equal (expected , actual )
@@ -378,13 +386,17 @@ def test_single_condition_less_than_floats_keep_first_numba(df, right):
378
386
allow_exact_matches = False ,
379
387
)
380
388
expected .index = range (len (expected ))
381
- actual = df [["B" ]].conditional_join (
382
- right [["Numeric" ]],
383
- ("B" , "Numeric" , "<" ),
384
- how = "left" ,
385
- sort_by_appearance = False ,
386
- keep = "first" ,
387
- use_numba = True ,
389
+ actual = (
390
+ df [["B" ]]
391
+ .conditional_join (
392
+ right [["Numeric" ]],
393
+ ("B" , "Numeric" , "<" ),
394
+ how = "left" ,
395
+ sort_by_appearance = False ,
396
+ keep = "first" ,
397
+ use_numba = True ,
398
+ )
399
+ .sort_values (["B" , "Numeric" ], ignore_index = True )
388
400
)
389
401
390
402
assert_frame_equal (expected , actual )
@@ -405,15 +417,21 @@ def test_single_condition_less_than_floats_keep_last_numba(df, right):
405
417
right_on = "Numeric" ,
406
418
direction = "backward" ,
407
419
allow_exact_matches = False ,
408
- )
420
+ ). sort_values ([ "B" , "Numeric" ], ascending = [ True , False ], ignore_index = True )
409
421
expected .index = range (len (expected ))
410
- actual = df [["B" ]].conditional_join (
411
- right [["Numeric" ]],
412
- ("B" , "Numeric" , ">" ),
413
- how = "left" ,
414
- sort_by_appearance = False ,
415
- keep = "last" ,
416
- use_numba = True ,
422
+ actual = (
423
+ df [["B" ]]
424
+ .conditional_join (
425
+ right [["Numeric" ]],
426
+ ("B" , "Numeric" , ">" ),
427
+ how = "left" ,
428
+ sort_by_appearance = False ,
429
+ keep = "last" ,
430
+ use_numba = True ,
431
+ )
432
+ .sort_values (
433
+ ["B" , "Numeric" ], ascending = [True , False ], ignore_index = True
434
+ )
417
435
)
418
436
419
437
assert_frame_equal (expected , actual )
@@ -1170,13 +1188,17 @@ def test_how_left(df, right):
1170
1188
expected = (
1171
1189
df [["A" ]]
1172
1190
.join (expected [["Integers" ]], how = "left" , sort = False )
1191
+ .sort_values (["A" , "Integers" ], ignore_index = True )
1173
1192
.reset_index (drop = True )
1174
1193
)
1175
- actual = df [["A" ]].conditional_join (
1176
- right [["Integers" ]],
1177
- ("A" , "Integers" , "<=" ),
1178
- how = "left" ,
1179
- sort_by_appearance = True ,
1194
+ actual = (
1195
+ df [["A" ]]
1196
+ .conditional_join (
1197
+ right [["Integers" ]],
1198
+ ("A" , "Integers" , "<=" ),
1199
+ how = "left" ,
1200
+ )
1201
+ .sort_values (["A" , "Integers" ], ignore_index = True )
1180
1202
)
1181
1203
1182
1204
assert_frame_equal (expected , actual )
@@ -1196,13 +1218,17 @@ def test_how_right(df, right):
1196
1218
expected = (
1197
1219
expected [["E" ]]
1198
1220
.join (right [["Dates" ]], how = "right" , sort = False )
1221
+ .sort_values (["E" , "Dates" ], ignore_index = True )
1199
1222
.reset_index (drop = True )
1200
1223
)
1201
- actual = df [["E" ]].conditional_join (
1202
- right [["Dates" ]],
1203
- ("E" , "Dates" , ">" ),
1204
- how = "right" ,
1205
- sort_by_appearance = True ,
1224
+ actual = (
1225
+ df [["E" ]]
1226
+ .conditional_join (
1227
+ right [["Dates" ]],
1228
+ ("E" , "Dates" , ">" ),
1229
+ how = "right" ,
1230
+ )
1231
+ .sort_values (["E" , "Dates" ], ignore_index = True )
1206
1232
)
1207
1233
1208
1234
assert_frame_equal (expected , actual )
@@ -1503,14 +1529,18 @@ def test_dual_conditions_gt_and_lt_numbers_left_join(df, right):
1503
1529
df [["B" ]]
1504
1530
.join (expected [["Numeric" , "Floats" ]], how = "left" , sort = False )
1505
1531
.reset_index (drop = True )
1506
- )
1532
+ ). sort_values ([ "B" , "Numeric" , "Floats" ], ignore_index = True )
1507
1533
1508
- actual = df [["B" ]].conditional_join (
1509
- right [["Numeric" , "Floats" ]],
1510
- ("B" , "Numeric" , ">" ),
1511
- ("B" , "Floats" , "<" ),
1512
- how = "left" ,
1513
- sort_by_appearance = True ,
1534
+ actual = (
1535
+ df [["B" ]]
1536
+ .conditional_join (
1537
+ right [["Numeric" , "Floats" ]],
1538
+ ("B" , "Numeric" , ">" ),
1539
+ ("B" , "Floats" , "<" ),
1540
+ how = "left" ,
1541
+ sort_by_appearance = True ,
1542
+ )
1543
+ .sort_values (["B" , "Numeric" , "Floats" ], ignore_index = True )
1514
1544
)
1515
1545
1516
1546
assert_frame_equal (expected , actual )
@@ -1539,15 +1569,19 @@ def test_dual_conditions_gt_and_lt_numbers_right_join(df, right):
1539
1569
expected = (
1540
1570
expected [["B" ]]
1541
1571
.join (right [["Numeric" , "Floats" ]], how = "right" , sort = False )
1572
+ .sort_values (["Numeric" , "Floats" , "B" ], ignore_index = True )
1542
1573
.reset_index (drop = True )
1543
1574
)
1544
1575
1545
- actual = df [["B" ]].conditional_join (
1546
- right [["Numeric" , "Floats" ]],
1547
- ("B" , "Numeric" , ">" ),
1548
- ("B" , "Floats" , "<" ),
1549
- how = "right" ,
1550
- sort_by_appearance = True ,
1576
+ actual = (
1577
+ df [["B" ]]
1578
+ .conditional_join (
1579
+ right [["Numeric" , "Floats" ]],
1580
+ ("B" , "Numeric" , ">" ),
1581
+ ("B" , "Floats" , "<" ),
1582
+ how = "right" ,
1583
+ )
1584
+ .sort_values (["Numeric" , "Floats" , "B" ], ignore_index = True )
1551
1585
)
1552
1586
assert_frame_equal (expected , actual )
1553
1587
@@ -1564,18 +1598,26 @@ def test_dual_ne_extension(df, right):
1564
1598
df = df .astype ({"A" : "Int64" })
1565
1599
right = right .astype ({"Integers" : "Int64" })
1566
1600
expected = df .merge (right , how = "cross" )
1567
- expected = expected .loc [
1568
- expected .A .ne (expected .Integers ) & expected .B .ne (expected .Numeric ),
1569
- filters ,
1570
- ].reset_index (drop = True )
1601
+ expected = (
1602
+ expected .loc [
1603
+ expected .A .ne (expected .Integers ) & expected .B .ne (expected .Numeric ),
1604
+ filters ,
1605
+ ]
1606
+ .reset_index (drop = True )
1607
+ .sort_values (filters , ignore_index = True )
1608
+ )
1571
1609
1572
- actual = df .conditional_join (
1573
- right ,
1574
- ("A" , "Integers" , "!=" ),
1575
- ("B" , "Numeric" , "!=" ),
1576
- how = "inner" ,
1577
- sort_by_appearance = True ,
1578
- ).filter (filters )
1610
+ actual = (
1611
+ df .conditional_join (
1612
+ right ,
1613
+ ("A" , "Integers" , "!=" ),
1614
+ ("B" , "Numeric" , "!=" ),
1615
+ how = "inner" ,
1616
+ sort_by_appearance = True ,
1617
+ )
1618
+ .filter (filters )
1619
+ .sort_values (filters , ignore_index = True )
1620
+ )
1579
1621
assert_frame_equal (expected , actual )
1580
1622
1581
1623
@@ -1623,19 +1665,27 @@ def test_dual_ne_numba_extension(df, right):
1623
1665
df = df .astype ({"A" : "Int64" })
1624
1666
right = right .astype ({"Integers" : "Int64" })
1625
1667
expected = df .merge (right , how = "cross" )
1626
- expected = expected .loc [
1627
- expected .A .ne (expected .Integers ) & expected .B .ne (expected .Numeric ),
1628
- filters ,
1629
- ].reset_index (drop = True )
1668
+ expected = (
1669
+ expected .loc [
1670
+ expected .A .ne (expected .Integers ) & expected .B .ne (expected .Numeric ),
1671
+ filters ,
1672
+ ]
1673
+ .reset_index (drop = True )
1674
+ .sort_values (filters , ignore_index = True )
1675
+ )
1630
1676
1631
- actual = df .conditional_join (
1632
- right ,
1633
- ("A" , "Integers" , "!=" ),
1634
- ("B" , "Numeric" , "!=" ),
1635
- how = "inner" ,
1636
- use_numba = True ,
1637
- sort_by_appearance = True ,
1638
- ).filter (filters )
1677
+ actual = (
1678
+ df .conditional_join (
1679
+ right ,
1680
+ ("A" , "Integers" , "!=" ),
1681
+ ("B" , "Numeric" , "!=" ),
1682
+ how = "inner" ,
1683
+ use_numba = True ,
1684
+ sort_by_appearance = True ,
1685
+ )
1686
+ .filter (filters )
1687
+ .sort_values (filters , ignore_index = True )
1688
+ )
1639
1689
assert_frame_equal (expected , actual )
1640
1690
1641
1691
0 commit comments