Skip to content

Commit 0cfc2ab

Browse files
ZanirPZanirP
ZanirP
authored and
ZanirP
committed
if statement changes
1 parent 8763b5e commit 0cfc2ab

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pandas/core/reshape/melt.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ def melt(
173173
1 b B E 3
174174
2 c B E 5
175175
"""
176-
# GH61475 - prevent AttributeError when duplicate column in id_vars
177-
if id_vars and any(frame.columns.tolist().count(col) > 1 for col in id_vars):
178-
raise ValueError("id_vars cannot contain duplicate columns.")
176+
179177
if value_name in frame.columns:
180178
raise ValueError(
181179
f"value_name ({value_name}) cannot match an element in "
@@ -185,6 +183,10 @@ def melt(
185183
value_vars_was_not_none = value_vars is not None
186184
value_vars = ensure_list_vars(value_vars, "value_vars", frame.columns)
187185

186+
# GH61475 - prevent AttributeError when duplicate column in id_vars
187+
if len(frame.columns.get_indexer_for(id_vars)) > len(id_vars):
188+
raise ValueError("id_vars cannot contain duplicate columns.")
189+
188190
if id_vars or value_vars:
189191
if col_level is not None:
190192
level = frame.columns.get_level_values(col_level)

0 commit comments

Comments
 (0)