Skip to content

[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

Merged
merged 9 commits into from
Jan 22, 2019

Conversation

pierretallotte
Copy link
Contributor

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?

@pierretallotte pierretallotte changed the title Convert the negative indices to positive ones in ColumnTransformer._get_column_indices [MRG] Convert the negative indices to positive ones in ColumnTransformer._get_column_indices Jan 19, 2019
Copy link
Member

@jnothman jnothman left a 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):
Copy link
Member

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)

jnothman
jnothman approved these changes Jan 20, 2019

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()
Copy link
Member

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]

Copy link
Member

@jnothman jnothman left a 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:

Copy link
Contributor

@albertcthomas albertcthomas left a comment

Choose a reason for hiding this comment

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

@jnothman jnothman added this to the 0.20.3 milestone Jan 21, 2019
Copy link
Member

@qinhanmin2014 qinhanmin2014 left a 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

@qinhanmin2014 qinhanmin2014 merged commit ce9dedb into scikit-learn:master Jan 22, 2019
@jorisvandenbossche
Copy link
Member

Thanks for the fix!

thomasjpfan pushed a commit to thomasjpfan/scikit-learn that referenced this pull request Feb 7, 2019
jnothman pushed a commit to jnothman/scikit-learn that referenced this pull request Feb 19, 2019
@jnothman jnothman mentioned this pull request Feb 19, 2019
17 tasks
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ColumnTransformer behavior for negative column indexes
5 participants