Skip to content

Commit 61cb83d

Browse files
trivialfisCopilot
andauthored
Validate unique column names in pandas. (#12199)
--------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent e8ba843 commit 61cb83d

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

python-package/xgboost/data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,11 @@ def _transform_pandas_df(
657657
) -> Tuple[PandasTransformed, Optional[FeatureNames], Optional[FeatureTypes]]:
658658
if meta and len(data.columns) > 1 and meta not in _matrix_meta:
659659
raise ValueError(f"DataFrame for {meta} cannot have multiple columns")
660+
if data.columns.has_duplicates:
661+
duplicates = data.columns[data.columns.duplicated()].unique().tolist()
662+
raise ValueError(
663+
f"Duplicate column names are not supported. Duplicates found: {duplicates}"
664+
)
660665

661666
feature_types, ref_categories = get_ref_categories(feature_types)
662667
feature_names, feature_types = pandas_feature_info(

0 commit comments

Comments
 (0)