Skip to content

Commit 62f7cd2

Browse files
code change based on reviews
1 parent 346de9a commit 62f7cd2

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

pandas/core/internals/managers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,12 +1973,22 @@ def items_overlap_with_suffix(left, lsuffix, right, rsuffix):
19731973

19741974
def lrenamer(x):
19751975
if x in to_rename:
1976-
return '{x}{lsuffix}'.format(x=x, lsuffix=lsuffix)
1976+
if lsuffix is None and isinstance(x, str):
1977+
return '{x}{lsuffix}'.format(x=x, lsuffix='')
1978+
elif lsuffix is None and isinstance(x, (float, int)):
1979+
return x
1980+
else:
1981+
return '{x}{lsuffix}'.format(x=x, lsuffix=lsuffix)
19771982
return x
19781983

19791984
def rrenamer(x):
19801985
if x in to_rename:
1981-
return '{x}{rsuffix}'.format(x=x, rsuffix=rsuffix)
1986+
if rsuffix is None and isinstance(x, str):
1987+
return '{x}{rsuffix}'.format(x=x, rsuffix='')
1988+
elif rsuffix is None and isinstance(x, (float, int)):
1989+
return x
1990+
else:
1991+
return '{x}{rsuffix}'.format(x=x, rsuffix=rsuffix)
19821992
return x
19831993

19841994
return (_transform_index(left, lrenamer),

pandas/core/reshape/merge.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,6 @@ def __init__(self, left, right, how='inner', on=None,
489489

490490
self.copy = copy
491491

492-
if suffixes[0] is None:
493-
suffixes = ('', suffixes[1])
494-
if suffixes[1] is None:
495-
suffixes = (suffixes[0], '')
496492
self.suffixes = suffixes
497493

498494
self.sort = sort

pandas/tests/reshape/merge/test_merge.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,9 +1512,13 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm):
15121512

15131513
@pytest.mark.parametrize("col1, col2, suffixes, expected_cols", [
15141514
(0, 0, ("", "_dup"), ["0", "0_dup"]),
1515-
(0, 0, (None, "_dup"), ["0", "0_dup"]),
1515+
(0, 0, (None, "_dup"), [0, "0_dup"]),
15161516
(0, 0, ("_x", "_y"), ["0_x", "0_y"]),
1517-
("a", 0, (None, "_y"), ["a", 0])
1517+
("a", 0, (None, "_y"), ["a", 0]),
1518+
(0.0, 0.0, ("_x", None), ["0.0_x", 0.0]),
1519+
("b", "b", (None, "_y"), ["b", "b_y"]),
1520+
("a", "a", ("_x", None), ["a_x", "a"]),
1521+
("a", "b", ("_x", None), ["a", "b"])
15181522
])
15191523
def test_merge_suffix(col1, col2, suffixes, expected_cols):
15201524
# issue: 24782

0 commit comments

Comments
 (0)