Repository navigation
Conversation
|
Thank you for opening your first pull request to scikit-learn! 🎉 To help get your contribution reviewed, please make sure that:
|
SequentialFeatureSelector converted dataframes to numpy arrays before slicing candidate feature subsets, so estimators relying on column names or dtypes (e.g. a pipeline with a ColumnTransformer using callable column selectors) could not be used for the selection. Skip the array conversion for pandas dataframes and slice candidate subsets with _safe_indexing, mirroring SelectorMixin.transform. Fixes scikit-learn#25711
arham766
force-pushed
the
sfs-preserve-dataframe-25711
branch
from
July 10, 2026 10:23
6ccabee to
e8f347f
Compare
This branch has not been deployed
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.
Reference Issues/PRs
Fixes #25711
What does this implement/fix? Explain your changes.
SequentialFeatureSelector.fitconvertedXto a numpy array before slicing candidate feature subsets, so the underlying estimator never saw column names or dtypes. This made it impossible to use estimators that rely on them — notably aPipelinecontaining aColumnTransformerwith callable column selectors, the pattern suggested in #25711 (comment).This PR preserves pandas dataframes in
fitviavalidate_data(..., skip_check_array=True)and slices candidate subsets with_safe_indexing(X, candidate_mask, axis=1), mirroring whatSelectorMixin.transformalready does to preserve dataframes. With this change the following works:ColumnTransformers configured with hard-coded positional indices still fail, as discussed in the issue — once features are subset, positional specs against the originalXare inherently ambiguous; callable selectors (or refitting semantics) are the supported route.An explicit check keeps the previous
ensure_min_features=2error message for dataframes. Numpy, sparse, and other inputs go through the exact same validation as before.Any other comments?
Behaviour change for pandas input: the inner estimator is now fitted on dataframe slices (original dtypes, no forced float conversion, no upfront NaN check — the estimator's own validation applies, consistent with the general meta-estimator delegation direction). Happy to adjust if full validation should be retained for the non-
ColumnTransformercase.