Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c9bfc5a

Browse filesBrowse files
committed
BUG: Raise MergeError when suffixes result in duplicate column names (GH#61402)
1 parent 2e141aa commit c9bfc5a
Copy full SHA for c9bfc5a

File tree

1 file changed

+15
-0
lines changed
Filter options

1 file changed

+15
-0
lines changed

‎pandas/core/reshape/merge.py

Copy file name to clipboardExpand all lines: pandas/core/reshape/merge.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,6 +3058,21 @@ def renamer(x, suffix: str | None):
30583058
llabels = left._transform_index(lrenamer)
30593059
rlabels = right._transform_index(rrenamer)
30603060

3061+
3062+
# Check for duplicates created by suffixes
3063+
left_collisions = llabels.intersection(right.difference(to_rename))
3064+
right_collisions = rlabels.intersection(left.difference(to_rename))
3065+
if len(left_collisions) > 0:
3066+
raise MergeError(
3067+
"Passing 'suffixes' which cause duplicate columns "
3068+
f"{set(left_collisions)} is not allowed."
3069+
)
3070+
if len(right_collisions) > 0:
3071+
raise MergeError(
3072+
"Passing 'suffixes' which cause duplicate columns "
3073+
f"{set(right_collisions)} is not allowed."
3074+
)
3075+
30613076
dups = []
30623077
if not llabels.is_unique:
30633078
# Only warn when duplicates are caused because of suffixes, already duplicated

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.