|
22 | 22 | from pandas.core.reshape.concat import concat
|
23 | 23 | from pandas.core.reshape.merge import MergeError, merge
|
24 | 24 | import pandas.util.testing as tm
|
25 |
| -from pandas.util.testing import assert_frame_equal, assert_series_equal |
| 25 | +from pandas.util.testing import assert_frame_equal, assert_series_equal, assert_index_equal |
26 | 26 |
|
27 | 27 | N = 50
|
28 | 28 | NGROUPS = 8
|
@@ -1442,3 +1442,20 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm):
|
1442 | 1442 | with pytest.raises(ValueError, match='a Series without a name'):
|
1443 | 1443 | result = pd.merge(a, b, on=on, left_on=left_on, right_on=right_on,
|
1444 | 1444 | left_index=left_index, right_index=right_index)
|
| 1445 | + |
| 1446 | + |
| 1447 | +@pytest.mark.parametrize("col1, col2, suffixes, expected_cols", [ |
| 1448 | + (0, 0, ("", "_dup"), ["0", "0_dup"]), |
| 1449 | + (0, 0, (None, "_dup"), ["0", "0_dup"]), |
| 1450 | + (0, 0, ("_x", "_y"), ["0_x", "0_y"]), |
| 1451 | + ("a", 0, (None, "_y"), ["a", 0]) |
| 1452 | +]) |
| 1453 | +def test_merge_suffix(col1, col2, suffixes, expected_cols): |
| 1454 | + a = pd.DataFrame({col1: [1, 2, 3]}) |
| 1455 | + b = pd.DataFrame({col2: [4, 5, 6]}) |
| 1456 | + |
| 1457 | + suffix_df = a.merge(b, left_index=True, right_index=True, suffixes=suffixes) |
| 1458 | + assert suffix_df.columns.tolist() == expected_cols |
| 1459 | + |
| 1460 | + with pytest.raises(ValueError): |
| 1461 | + a.merge(b, left_index=True, right_index=True, suffixes=(None, None)) |
0 commit comments