Skip to content

Commit 2620d0b

Browse files
code change based on reviews
1 parent 4def5dd commit 2620d0b

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
@@ -1965,12 +1965,22 @@ def items_overlap_with_suffix(left, lsuffix, right, rsuffix):
19651965

19661966
def lrenamer(x):
19671967
if x in to_rename:
1968-
return '{x}{lsuffix}'.format(x=x, lsuffix=lsuffix)
1968+
if lsuffix is None and isinstance(x, str):
1969+
return '{x}{lsuffix}'.format(x=x, lsuffix='')
1970+
elif lsuffix is None and isinstance(x, (float, int)):
1971+
return x
1972+
else:
1973+
return '{x}{lsuffix}'.format(x=x, lsuffix=lsuffix)
19691974
return x
19701975

19711976
def rrenamer(x):
19721977
if x in to_rename:
1973-
return '{x}{rsuffix}'.format(x=x, rsuffix=rsuffix)
1978+
if rsuffix is None and isinstance(x, str):
1979+
return '{x}{rsuffix}'.format(x=x, rsuffix='')
1980+
elif rsuffix is None and isinstance(x, (float, int)):
1981+
return x
1982+
else:
1983+
return '{x}{rsuffix}'.format(x=x, rsuffix=rsuffix)
19741984
return x
19751985

19761986
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
@@ -1446,9 +1446,13 @@ def test_merge_series(on, left_on, right_on, left_index, right_index, nm):
14461446

14471447
@pytest.mark.parametrize("col1, col2, suffixes, expected_cols", [
14481448
(0, 0, ("", "_dup"), ["0", "0_dup"]),
1449-
(0, 0, (None, "_dup"), ["0", "0_dup"]),
1449+
(0, 0, (None, "_dup"), [0, "0_dup"]),
14501450
(0, 0, ("_x", "_y"), ["0_x", "0_y"]),
1451-
("a", 0, (None, "_y"), ["a", 0])
1451+
("a", 0, (None, "_y"), ["a", 0]),
1452+
(0.0, 0.0, ("_x", None), ["0.0_x", 0.0]),
1453+
("b", "b", (None, "_y"), ["b", "b_y"]),
1454+
("a", "a", ("_x", None), ["a_x", "a"]),
1455+
("a", "b", ("_x", None), ["a", "b"])
14521456
])
14531457
def test_merge_suffix(col1, col2, suffixes, expected_cols):
14541458
# issue: 24782

0 commit comments

Comments
 (0)