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 ad744df

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

File tree

1 file changed

+14
-0
lines changed
Filter options

1 file changed

+14
-0
lines changed

‎pandas/core/reshape/merge.py

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

3061+
# Check for duplicates created by suffixes
3062+
left_collisions = llabels.intersection(right.difference(to_rename))
3063+
right_collisions = rlabels.intersection(left.difference(to_rename))
3064+
if len(left_collisions) > 0:
3065+
raise MergeError(
3066+
"Passing 'suffixes' which cause duplicate columns "
3067+
f"{set(left_collisions)} is not allowed"
3068+
)
3069+
if len(right_collisions) > 0:
3070+
raise MergeError(
3071+
"Passing 'suffixes' which cause duplicate columns "
3072+
f"{set(right_collisions)} is not allowed"
3073+
)
3074+
30613075
dups = []
30623076
if not llabels.is_unique:
30633077
# 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.