@@ -1526,3 +1526,65 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm):
15261526 with pytest .raises (ValueError , match = msg ):
15271527 result = pd .merge (a , b , on = on , left_on = left_on , right_on = right_on ,
15281528 left_index = left_index , right_index = right_index )
1529+
1530+
1531+ @pytest .mark .parametrize ("col1, col2, kwargs, expected_cols" , [
1532+ (0 , 0 , dict (suffixes = ("" , "_dup" )), ["0" , "0_dup" ]),
1533+ (0 , 0 , dict (suffixes = (None , "_dup" )), [0 , "0_dup" ]),
1534+ (0 , 0 , dict (suffixes = ("_x" , "_y" )), ["0_x" , "0_y" ]),
1535+ ("a" , 0 , dict (suffixes = (None , "_y" )), ["a" , 0 ]),
1536+ (0.0 , 0.0 , dict (suffixes = ("_x" , None )), ["0.0_x" , 0.0 ]),
1537+ ("b" , "b" , dict (suffixes = (None , "_y" )), ["b" , "b_y" ]),
1538+ ("a" , "a" , dict (suffixes = ("_x" , None )), ["a_x" , "a" ]),
1539+ ("a" , "b" , dict (suffixes = ("_x" , None )), ["a" , "b" ]),
1540+ ("a" , "a" , dict (suffixes = [None , "_x" ]), ["a" , "a_x" ]),
1541+ (0 , 0 , dict (suffixes = ["_a" , None ]), ["0_a" , 0 ]),
1542+ ("a" , "a" , dict (), ["a_x" , "a_y" ]),
1543+ (0 , 0 , dict (), ["0_x" , "0_y" ])
1544+ ])
1545+ def test_merge_suffix (col1 , col2 , kwargs , expected_cols ):
1546+ # issue: 24782
1547+ a = pd .DataFrame ({col1 : [1 , 2 , 3 ]})
1548+ b = pd .DataFrame ({col2 : [4 , 5 , 6 ]})
1549+
1550+ expected = pd .DataFrame ([[1 , 4 ], [2 , 5 ], [3 , 6 ]],
1551+ columns = expected_cols )
1552+
1553+ result = a .merge (b , left_index = True , right_index = True , ** kwargs )
1554+ tm .assert_frame_equal (result , expected )
1555+
1556+ result = pd .merge (a , b , left_index = True , right_index = True , ** kwargs )
1557+ tm .assert_frame_equal (result , expected )
1558+
1559+
1560+ @pytest .mark .parametrize ("col1, col2, suffixes" , [
1561+ ("a" , "a" , [None , None ]),
1562+ ("a" , "a" , (None , None )),
1563+ ("a" , "a" , ("" , None )),
1564+ (0 , 0 , [None , None ]),
1565+ (0 , 0 , (None , "" ))
1566+ ])
1567+ def test_merge_suffix_error (col1 , col2 , suffixes ):
1568+ # issue: 24782
1569+ a = pd .DataFrame ({col1 : [1 , 2 , 3 ]})
1570+ b = pd .DataFrame ({col2 : [3 , 4 , 5 ]})
1571+
1572+ # TODO: might reconsider current raise behaviour, see issue 24782
1573+ msg = "columns overlap but no suffix specified"
1574+ with pytest .raises (ValueError , match = msg ):
1575+ pd .merge (a , b , left_index = True , right_index = True , suffixes = suffixes )
1576+
1577+
1578+ @pytest .mark .parametrize ("col1, col2, suffixes" , [
1579+ ("a" , "a" , None ),
1580+ (0 , 0 , None )
1581+ ])
1582+ def test_merge_suffix_none_error (col1 , col2 , suffixes ):
1583+ # issue: 24782
1584+ a = pd .DataFrame ({col1 : [1 , 2 , 3 ]})
1585+ b = pd .DataFrame ({col2 : [3 , 4 , 5 ]})
1586+
1587+ # TODO: might reconsider current raise behaviour, see GH24782
1588+ msg = "iterable"
1589+ with pytest .raises (TypeError , match = msg ):
1590+ pd .merge (a , b , left_index = True , right_index = True , suffixes = suffixes )
0 commit comments