Skip to content

Merge nonstring columns #46879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix test
  • Loading branch information
ericman93 committed Apr 26, 2022
commit cb22a1e64a03a57c7b1ed78da1f2b7e2d5187b5e
6 changes: 6 additions & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,12 @@ Strings
- Bug in :meth:`str.startswith` and :meth:`str.endswith` when using other series as parameter _pat_. Now raises ``TypeError`` (:issue:`3485`)
-

Merge
^^^^^^^
- Bug in :meth:`merge` supports complex types merge with identical columns
-


Interval
^^^^^^^^
- Bug in :meth:`IntervalArray.__setitem__` when setting ``np.nan`` into an integer-backed array raising ``ValueError`` instead of ``TypeError`` (:issue:`45484`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,7 @@ def renamer(x, suffix):
-------
x : renamed column
"""
if x in to_rename and isinstance(x, str) and suffix is not None:
if x in to_rename and isinstance(x, (str, int, float)) and suffix is not None:
return f"{x}{suffix}"
return x

Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/reshape/merge/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2669,3 +2669,16 @@ def test_merge_different_index_names():
result = merge(left, right, left_on="c", right_on="d")
expected = DataFrame({"a_x": [1], "a_y": 1})
tm.assert_frame_equal(result, expected)


def test_merge_complex_column():
class Column:
def __init__(self, name):
self.name = name

merged_column = Column(name='Z')
left = DataFrame({merged_column: [1], 'X': [2]})
right = DataFrame({merged_column: [1], 'Y': [6]})
result = merge(left, right, left_index=True, right_index=True)
expected = DataFrame([[1, 2, 1, 6]], columns=[merged_column, 'X', merged_column, 'Y'])
tm.assert_frame_equal(result, expected)