Skip to content

Commit 0da71fe

Browse files
simplify code and add tests
1 parent acffc0d commit 0da71fe

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

pandas/core/internals/managers.py

+4-10
Original file line numberDiff line numberDiff line change
@@ -1972,19 +1972,13 @@ def items_overlap_with_suffix(left, lsuffix, right, rsuffix):
19721972
'{rename}'.format(rename=to_rename))
19731973

19741974
def lrenamer(x):
1975-
if x in to_rename:
1976-
if lsuffix is None:
1977-
return x
1978-
else:
1979-
return '{x}{lsuffix}'.format(x=x, lsuffix=lsuffix)
1975+
if x in to_rename and lsuffix is not None:
1976+
return '{x}{lsuffix}'.format(x=x, lsuffix=lsuffix)
19801977
return x
19811978

19821979
def rrenamer(x):
1983-
if x in to_rename:
1984-
if rsuffix is None:
1985-
return x
1986-
else:
1987-
return '{x}{rsuffix}'.format(x=x, rsuffix=rsuffix)
1980+
if x in to_rename and rsuffix is not None:
1981+
return '{x}{rsuffix}'.format(x=x, rsuffix=rsuffix)
19881982
return x
19891983

19901984
return (_transform_index(left, lrenamer),

pandas/tests/reshape/merge/test_merge.py

+13
Original file line numberDiff line numberDiff line change
@@ -1549,3 +1549,16 @@ def test_merge_suffix_errors(suffixes):
15491549
with pytest.raises(ValueError,
15501550
match="columns overlap but no suffix specified"):
15511551
a.merge(b, left_index=True, right_index=True, suffixes=suffixes)
1552+
1553+
1554+
@pytest.mark.parametrize("col1, col2, expected_cols", [
1555+
("a", "a", ["a_x", "a_y"]),
1556+
(0, 0, ["0_x", "0_y"])
1557+
])
1558+
def test_merge_default_suffix(col1, col2, expected_cols):
1559+
a = pd.DataFrame({col1: [1, 2]})
1560+
b = pd.DataFrame({col2: [3, 4]})
1561+
1562+
expected = pd.DataFrame([[1, 3], [2, 4]], columns=expected_cols)
1563+
result = a.merge(b, left_index=True, right_index=True)
1564+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)