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
[MRG] Raise error in OneHotEncoder.inverse_transform #14982
[MRG] Raise error in OneHotEncoder.inverse_transform #14982
Conversation
c51565d
to
d9bce70
Compare
Hi @jnothman, please review my PR :) |
Hi @kwinata, please, forgive us! Your PR clearly needed more attention! |
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.
Thank you @kwinata !
sklearn/preprocessing/_encoders.py
Outdated
dropped = np.asarray(sub.sum(axis=1) == 0).flatten() | ||
if dropped.any(): | ||
X_tr[dropped, i] = self.categories_[i][self.drop_idx_[i]] | ||
if self.drop is None: | ||
raise ValueError("Unknown value in row {}".format(i)) |
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.
i
is the feature index not the row. The rows are in np.flatnonzero(dropped)
. The message can be more explicit:
The follow samples do not have an inverse when drop=None and handle_unknown='error' because they are all zeros: [0, 1, 2].
sklearn/preprocessing/_encoders.py
Outdated
X_tr[dropped, i] = self.categories_[i][self.drop_idx_[i]] | ||
if self.drop is None: | ||
raise ValueError("Unknown value in row {}".format(i)) | ||
else: |
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.
Nit: I prefer to remove the else
to un-indent the X_tr[dropped, ...]
line
12eb07d
to
b64a96d
Compare
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.
Please add an entry to the change log at doc/whats_new/v0.24.rst
with tag |Fix|. Like the other entries there, please reference this pull request with :pr:
and credit yourself (and other contributors if applicable) with :user:
.
dee5876
to
0a03d2e
Compare
Hi @thomasjpfan , I've added the changelog. Sorry for the messy |
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
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 @kwinata!
Thanks for your patience @kwinata! Do you mind fixing conflicts? Then maybe @glemaitre could have a look? Thanks! |
@cmarmo I've fixed the merge conflict. (@glemaitre ) |
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.
I fixed the conflict and just isolated the test in a specific test to have a link to the original issue.
I will wait that the CIs are passing (apart of the MacOS that is currently failing for some other reasons).
Reference Issues/PRs
Fixes #14934
What does this implement/fix? Explain your changes.
Add case for throwing exception as expected.
Any other comments?
NA