Skip to content

FIX: Fixed duplicate column error appearing with FeatureUnion polars - #32853

Merged
ogrisel merged 6 commits into
scikit-learn:mainfrom
leweex95:fix-featureunion-polars-duplicates
Jan 27, 2026
Merged

ogrisel merged 6 commits into
scikit-learn:mainfrom
leweex95:fix-featureunion-polars-duplicates

Conversation

@leweex95

@leweex95 leweex95 commented Dec 7, 2025 •

Copy link
Copy Markdown
Contributor

When using FeatureUnion with set_config(transform_output="polars"), the operation failed with polars.exceptions.DuplicateError because the ContainerAdapterProtocol.hstack() interface was incomplete: it didn't accept a feature_names parameter to apply column renaming before concatenation.

Fixes #32852

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. It looks correct to me but I think the testing of pandas and polars should be decoupled:

Comment thread sklearn/tests/test_pipeline.py Resolved
leweex95 and others added 2 commits December 8, 2025 20:18
@adrinjalali adrinjalali added this to Labs Dec 11, 2025
@adrinjalali adrinjalali moved this to Todo in Labs Dec 11, 2025
@adrinjalali adrinjalali moved this from Todo to In progress in Labs Dec 11, 2025

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late feedback. LGTM!

@ogrisel

ogrisel commented Jan 26, 2026

Copy link
Copy Markdown
Member

I synced this PR with main to get it to run with pandas 3.

@ogrisel ogrisel added Quick Review For PRs that are quick to review Waiting for Second Reviewer First reviewer is done, need a second one! labels Jan 26, 2026

@betatim betatim left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

One small comment: for bug reports like #32852 that come with a good and short reproducer we sometimes include an explicit test with the reproducer and a comment saying "non regression test for gh-32852". I think we test the relevant functionality already in test_feature_union_set_output (the reason it didn't catch the bug is because we didn't test with polars), but maybe it makes sense to add that non regression test

When I checkout this PR locally and run the following snippet everything works:

from sklearn.pipeline import FeatureUnion
from sklearn.preprocessing import StandardScaler
from sklearn import set_config
import numpy as np
set_config(transform_output="polars")
X = np.array([[1, 2], [3, 4], [5, 6]])
union = FeatureUnion([
    ("scaler1", StandardScaler()),
    ("scaler2", StandardScaler())
])
result = union.fit_transform(X)

@ogrisel

ogrisel commented Jan 27, 2026

Copy link
Copy Markdown
Member

but maybe it makes sense to add that non regression test

I don't think we need an extra non regression test since the existing test updated in this PR covers the polars case now. I would rather avoid redundant tests.

@ogrisel
ogrisel merged commit 2efd6ad into scikit-learn:main Jan 27, 2026
@github-project-automation github-project-automation Bot moved this from In progress to Done in Labs Jan 27, 2026
jeremiedbb added a commit to jeremiedbb/scikit-learn that referenced this pull request Feb 15, 2026
@jeremiedbb

Copy link
Copy Markdown
Member

I don't think we need an extra non regression test since the existing test updated in this PR covers the polars case now. I would rather avoid redundant tests.

A non-regression test would have been useful here 😄
The modified test was already passing on main. It does not meet the conditions that triggers the issue reported in #32852, i.e. duplicate column names.

Also, this PR did not completely fix the issue and introduced a regression at the same time because it did not take transformers that don't implement get_feature_names_out into account. So now FeatureUnion always fail on pandas and polars dataframes even without duplicate names.

The fixed that I proposed before this PR in #32106 is a more robust fix and removes the newly introduced regression. @betatim since you reviewed this one, maybe you can have a look ?

@adrinjalali adrinjalali removed this from Labs Mar 9, 2026
tonybaloney pushed a commit to tonybaloney/swe-complex-scikit-learn that referenced this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:pipeline module:utils Quick Review For PRs that are quick to review Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FeatureUnion with polars output fails due to missing column renaming in adapter interface

4 participants