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