feat: Enable EstimatorTransformer.get_feature_names_out via ClassNamePrefixFeaturesOutMixin mixin - #812
Merged
Conversation
EstimatorTransformer inherits TransformerMixin, which does not supply get_feature_names_out, so calling it raised AttributeError and any pipeline containing the transformer could not report its feature names either. Its output is not one-to-one with the input columns - one column per target, or a single column otherwise - so it now also inherits ClassNamePrefixFeaturesOutMixin and exposes _n_features_out, which is the sklearn convention for that shape. n_outputs_ is recorded during fit.
Contributor
|
Appreciate you picking this up. I forgot about it |
EstimatorTransformer.get_feature_names_out via ClassNamePrefixFeaturesOutMixin mixin
FBruzzesi
reviewed
Jul 26, 2026
Owner
|
I've been behind on reviews, sorry about that. I think I am cool with the version bump. It's been a few years at this point and the main thing that's important is that it doesn't increase the maintainance burden for us. |
…feature-names # Conflicts: # pyproject.toml # uv.lock
koaning
approved these changes
Aug 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
EstimatorTransformerinheritsTransformerMixin, which does not supplyget_feature_names_out, so the method simply isn't there:The practical symptom is the pipeline case, which fails even after fitting:
The transformer's output is not one-to-one with the input columns —
transformreturns one column per target for a multi-output estimator and reshapes to a single column otherwise — soOneToOneFeatureMixinwould be wrong here. The sklearn convention for this shape isClassNamePrefixFeaturesOutMixinplus a_n_features_out, which is what this adds;n_outputs_is recorded duringfit.In every case the number of names equals
transform(X).shape[1], which is asserted in the tests rather than assumed. A side benefit is thatset_output(transform="pandas")now yields a properly-named DataFrame instead of failing.@koaning — this is the change you green-lit on #533 back in 2022 ("Yes please!"); @CarloLepelaars offered then but no PR followed, and nothing open touches this file, so I hope it's helpful rather than stepping on anyone.
Fixes #533
Type of change
Checklist:
ruff checkandruff format --checkboth cleanparametrize_with_checkssuite still passes, and the names/width equality is assertedtests/test_meta/goes from 1073 passed to 1110 passed with the same 15 pre-existing collection errors (missingpyarrowlocally). Reverting onlyestimator_transformer.pywhile keeping the tests fails 37 of them, so they do guard the change.One thing I found while measuring the output width, which I have not touched because it is a separate bug and a behaviour change:
transformdoesoutput.reshape(-1, 1)whenevermulti_output_isFalse. Withpredict_func="predict_proba"and a 1-Dy,predict_probareturns(n_samples, n_classes), so the reshape multiplies the rows:The class docstring records this too — its example is 150 samples with
predict_func="predict_proba"and statesShape of transformed data: (300, 1). Happy to open a separate issue, or a PR, if you'd like it fixed.