@@ -1369,25 +1369,29 @@ def test_merge_on_indexes(self):
1369
1369
tm .assert_frame_equal (result , expected )
1370
1370
1371
1371
# how='left'
1372
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , how = 'left' )
1372
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1373
+ how = 'left' )
1373
1374
expected = pd .DataFrame ({'a' : [20 , 10 , 0 ], 'b' : [200 , 100 , np .nan ]},
1374
1375
index = [2 , 1 , 0 ])
1375
1376
tm .assert_frame_equal (result , expected )
1376
1377
1377
1378
# how='right'
1378
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , how = 'right' )
1379
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1380
+ how = 'right' )
1379
1381
expected = pd .DataFrame ({'a' : [10 , 20 , np .nan ], 'b' : [100 , 200 , 300 ]},
1380
1382
index = [1 , 2 , 3 ])
1381
1383
tm .assert_frame_equal (result , expected )
1382
1384
1383
1385
# how='inner'
1384
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , how = 'inner' )
1386
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1387
+ how = 'inner' )
1385
1388
expected = pd .DataFrame ({'a' : [20 , 10 ], 'b' : [200 , 100 ]},
1386
1389
index = [2 , 1 ])
1387
1390
tm .assert_frame_equal (result , expected )
1388
1391
1389
1392
# how='outer'
1390
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , how = 'outer' )
1393
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1394
+ how = 'outer' )
1391
1395
expected = pd .DataFrame ({'a' : [0 , 10 , 20 , np .nan ],
1392
1396
'b' : [np .nan , 100 , 200 , 300 ]},
1393
1397
index = [0 , 1 , 2 , 3 ])
@@ -1398,37 +1402,43 @@ def test_merge_on_indexes_sort(self):
1398
1402
df2 = pd .DataFrame ({'b' : [100 , 200 , 300 ]}, index = [1 , 2 , 3 ])
1399
1403
1400
1404
# default how='inner'
1401
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , sort = True )
1405
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1406
+ sort = True )
1402
1407
expected = pd .DataFrame ({'a' : [10 , 20 ], 'b' : [100 , 200 ]},
1403
1408
index = [1 , 2 ])
1404
1409
tm .assert_frame_equal (result , expected )
1405
1410
1406
1411
# how='left'
1407
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , how = 'left' , sort = True )
1412
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1413
+ how = 'left' , sort = True )
1408
1414
expected = pd .DataFrame ({'a' : [0 , 10 , 20 ], 'b' : [np .nan , 100 , 200 ]},
1409
1415
index = [0 , 1 , 2 ])
1410
1416
tm .assert_frame_equal (result , expected )
1411
1417
1412
1418
# how='right' (already sorted)
1413
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , how = 'right' , sort = True )
1419
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1420
+ how = 'right' , sort = True )
1414
1421
expected = pd .DataFrame ({'a' : [10 , 20 , np .nan ], 'b' : [100 , 200 , 300 ]},
1415
1422
index = [1 , 2 , 3 ])
1416
1423
tm .assert_frame_equal (result , expected )
1417
1424
1418
1425
# how='right'
1419
- result = pd .merge (df2 , df1 , left_index = True , right_index = True , how = 'right' , sort = True )
1426
+ result = pd .merge (df2 , df1 , left_index = True , right_index = True ,
1427
+ how = 'right' , sort = True )
1420
1428
expected = pd .DataFrame ([[np .nan , 0 ], [100 , 10 ], [200 , 20 ]],
1421
1429
columns = ['b' , 'a' ], index = [0 , 1 , 2 ])
1422
1430
tm .assert_frame_equal (result , expected )
1423
1431
1424
1432
# how='inner'
1425
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , how = 'inner' , sort = True )
1433
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1434
+ how = 'inner' , sort = True )
1426
1435
expected = pd .DataFrame ({'a' : [10 , 20 ], 'b' : [100 , 200 ]},
1427
1436
index = [1 , 2 ])
1428
1437
tm .assert_frame_equal (result , expected )
1429
1438
1430
1439
# how='outer'
1431
- result = pd .merge (df1 , df2 , left_index = True , right_index = True , how = 'outer' , sort = True )
1440
+ result = pd .merge (df1 , df2 , left_index = True , right_index = True ,
1441
+ how = 'outer' , sort = True )
1432
1442
expected = pd .DataFrame ({'a' : [0 , 10 , 20 , np .nan ],
1433
1443
'b' : [np .nan , 100 , 200 , 300 ]},
1434
1444
index = [0 , 1 , 2 , 3 ])
0 commit comments