Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX Fix ColumnTransformer.get_feature_names_out with slices - #22775

Merged
thomasjpfan merged 4 commits into
scikit-learn:mainfrom
randomgeek78:patch-1
Mar 15, 2022
Merged

FIX Fix ColumnTransformer.get_feature_names_out with slices#22775
thomasjpfan merged 4 commits into
scikit-learn:mainfrom
randomgeek78:patch-1

Conversation

@randomgeek78

Copy link
Copy Markdown
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?

@adrinjalali adrinjalali 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.

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.

Comment thread sklearn/compose/_column_transformer.py

@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.

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

@thomasjpfan thomasjpfan 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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@thomasjpfan thomasjpfan 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.

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