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
ENH Improves efficiency of ColumnTransformer for string keys #16431
ENH Improves efficiency of ColumnTransformer for string keys #16431
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, aside for one comment below. Thanks @thomasjpfan !
else: | ||
stop = n_columns + 1 | ||
return list(range(n_columns)[slice(start, stop)]) | ||
else: | ||
columns = list(key) | ||
|
||
try: | ||
column_indices = [all_columns.index(col) for col in columns] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have some test, to gracefully fail with duplicate columns names, where get_loc
wouldn't behave as expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not have a test for this behavior. The original behavior uses index
, which returns the first appearance of the column name.
I would consider this a bug and error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated PR with a check on the return of get_loc
.
Please add an Efficiency entry to the change log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some nitpicks otherwise LGTM
sklearn/utils/__init__.py
Outdated
column_indices = [] | ||
for col in columns: | ||
col_idx = all_columns.get_loc(col) | ||
if not isinstance(col_idx, int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not isinstance(col_idx, int): | |
if not isinstance(col_idx, numbers.Integer): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
numbers.Integer
does not exist :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh Integral sorry
Thanks @thomasjpfan |
Reference Issues/PRs
Fixes #16327
What does this implement/fix? Explain your changes.
Uses the pandas index to find column indices
Any other comments?
Is a benchmark for this PR
This PR
master