Skip to content

FIX Fix ColumnTransformer.get_feature_names_out with slices #22775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 15, 2022

Conversation

randomgeek78
Copy link
Contributor

Reference Issues/PRs

Fixes #22774

What does this implement/fix? Explain your changes.

Currently, ColumnTransformer's get_feature_names_out does not work when the columns are specified as slices. This fix makes get_feature_names_out work properly with slices as well.

Any other comments?

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Please also add a regression test (to test the new behavior does what it should), and add a what_new entry under the 1.1 version.

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix and the non-regression test!

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! I left minor comments on adjust the tests to test slices with more than one element.

Comment on lines 1760 to 1767
(
[
("bycol1", TransWithNames(), slice(1, 2)),
("bycol2", "drop", ["d"]),
],
"passthrough",
["bycol1__b", "remainder__a", "remainder__c"],
),
Copy link
Member

Choose a reason for hiding this comment

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

May we update this example to have a slice with more than one element?

        (
            [
                ("bycol1", TransWithNames(), slice(1, 3)),
            ],
            "drop",
            ["bycol1__b", "bycol1__c"],
        ),

Comment on lines 1876 to 1881
[
("bycol1", TransWithNames(), ["d", "c"]),
("bycol2", "passthrough", slice(0, 1)),
],
"drop",
["d", "c", "a"],
Copy link
Member

Choose a reason for hiding this comment

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

Same here regarding slicing with more than one element:

Suggested change
[
("bycol1", TransWithNames(), ["d", "c"]),
("bycol2", "passthrough", slice(0, 1)),
],
"drop",
["d", "c", "a"],
[
("bycol1", TransWithNames(), ["d", "c"]),
("bycol2", "passthrough", slice(0, 2)),
],
"drop",
["d", "c", "a", "b"],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ogrisel @thomasjpfan Thanks for your feedback. I have pushed another commit incorporating your suggestions. Tx

@thomasjpfan thomasjpfan changed the title Making ColumnTransformer's get_feature_names_out to work with slices FIX Making ColumnTransformer's get_feature_names_out to work with slices Mar 14, 2022
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

LGTM

@thomasjpfan thomasjpfan changed the title FIX Making ColumnTransformer's get_feature_names_out to work with slices FIX Fix ColumnTransformer.get_feature_names_out with slices Mar 15, 2022
@thomasjpfan thomasjpfan merged commit fbfe98f into scikit-learn:main Mar 15, 2022
@randomgeek78 randomgeek78 deleted the patch-1 branch March 15, 2022 19:14
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ColumnTransformer's get_feature_names_out does not work properly with slices
4 participants