-
-
Notifications
You must be signed in to change notification settings - Fork 26k
[MRG] Convert the negative indices to positive ones in ColumnTransformer._get_column_indices #13017
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
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.
This looks great apart from some duplicated code
@@ -630,11 +630,11 @@ def _get_column_indices(X, key): | |||
|
|||
if _check_key_type(key, 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.
We could simplify this code to:
if _check_key_type(key, str):
...
else:
return np.atleast_1d(np.arange(n_columns)[key]).tolist()
(maybe with a check that it's also at most 1d)
|
||
if (_check_key_type(key, int) | ||
or hasattr(key, 'dtype') and np.issubdtype(key.dtype, np.bool_)): | ||
return np.atleast_1d(np.arange(n_columns)[key]).tolist() |
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.
Now that I see it, this is a little hard to read.
Maybe add a comment # Interpret the index like numpy does
or pull out idx = np.arange(n_columns)[key]
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.
Thanks!
Please add an entry to the change log at doc/whats_new/v0.20.rst
under 0.20.3. Like the other entries there, please reference this pull request with :issue:
and credit yourself (and other contributors if applicable) with :user:
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.
Thanks @pierretallotte
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.
thanks @pierretallotte I've moved the what's new entry to the correct place, will merge when green
Thanks for the fix! |
…r._get_column_indices (scikit-learn#13017)
…r._get_column_indices (scikit-learn#13017)
…r._get_column_indices (scikit-learn#13017)
…ansformer._get_column_indices (scikit-learn#13017)" This reverts commit ed39d15.
…ansformer._get_column_indices (scikit-learn#13017)" This reverts commit ed39d15.
…r._get_column_indices (scikit-learn#13017)
Reference Issues/PRs
Fixes #12946
What does this implement/fix? Explain your changes.
The negative indexes are now converted into positive ones when _get_column_indices is called.
I also add a test case as described in the issue.
Any other comments?