Skip to content

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

Closed

Description

@nocoding03

Describe the bug

When using FeatureUnion with set_config(transform_output="polars"), the operation fails with polars.exceptions.DuplicateError because the ContainerAdapterProtocol.hstack() interface is incomplete - it doesn't accept feature_names parameter to apply column renaming before concatenation.

The verbose_feature_names_out=True (default) mechanism should ensure unique column names via get_feature_names_out(), but this information cannot be passed to the adapter's hstack() method due to interface design limitation.

Steps/Code to Reproduce

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)

Expected Results

The code should work and produce a polars DataFrame with uniquely named columns like ['scaler1__x0', 'scaler1__x1', 'scaler2__x0', 'scaler2__x1'], consistent with the design of verbose_feature_names_out=True.

Actual Results

Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "/path/to/sklearn/utils/_set_output.py", line 316, in wrapped
    data_to_wrap = f(self, X, *args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/sklearn/pipeline.py", line 1971, in fit_transform
    return self._hstack(Xs)
           ^^^^^^^^^^^^^^^^
  File "/path/to/sklearn/pipeline.py", line 2052, in _hstack
    return adapter.hstack(Xs)
           ^^^^^^^^^^^^^^^^^^
  File "/path/to/sklearn/utils/_set_output.py", line 183, in hstack
    return pl.concat(Xs, how="horizontal")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/polars/functions/eager.py", line 256, in concat
    out = wrap_df(plr.concat_df_horizontal(elems))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
polars.exceptions.DuplicateError: column with name 'x0' has more than one occurrence

Versions

System:
    python: 3.11.14 | packaged by conda-forge | (main, Oct 22 2025, 22:46:25) [GCC 14.3.0]
executable: /opt/conda/envs/sklearn-dev/bin/python
   machine: Linux-6.8.0-65-generic-x86_64-with-glibc2.36

Python dependencies:
      sklearn: 1.9.dev0
          pip: 25.3
   setuptools: 80.9.0
        numpy: 2.3.5
        scipy: 1.16.3
       Cython: 3.2.2
       pandas: 2.3.3
   matplotlib: None
       joblib: 1.5.2
threadpoolctl: 3.6.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 48
         prefix: libopenblas
       filepath: /opt/conda/envs/sklearn-dev/lib/libopenblasp-r0.3.30.so
        version: 0.3.30
threading_layer: pthreads
   architecture: SkylakeX

       user_api: openmp
   internal_api: openmp
    num_threads: 48
         prefix: libgomp
       filepath: /opt/conda/envs/sklearn-dev/lib/libgomp.so.1.0.0
        version: None

Activity

  1. added
    Needs Triage
    on Dec 7, 2025
  2. nocoding03 commented on Dec 7, 2025

    @nocoding03
    ContributorAuthor

    reference : #32121

  3. removed
    Needs Triage
    on Dec 8, 2025
  4. ogrisel commented on Dec 8, 2025

    @ogrisel
    Member

    Thanks for the high quality report. I confirm I can reproduce the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions