-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[MRG + 1] Fix ValueError in LabelEncoder when using inverse_transform on unseen labels #9816
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing 8000 h2>
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,8 +203,10 @@ def test_label_encoder_errors(): | |
|
||
# Fail on unseen labels | ||
le = LabelEncoder() | ||
le.fit([1, 2, 3, 1, -1]) | ||
assert_raises(ValueError, le.inverse_transform, [-1]) | ||
le.fit([1, 2, 3, -1, 1]) | ||
msg = "contains previously unseen labels" | ||
assert_raise_message(ValueError, msg, le.inverse_transform, [-2]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find the organization of the tests a bit weird but not your fault. The test that it actually works if they are present is way at the top of the file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to reorganise tomorrow if you are able to give me some pointers - I'm not very familiar with the testing structure of sklearn as this is my first issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's fine, I think. |
||
assert_raise_message(ValueError, msg, le.inverse_transform, [-2, -3, -4]) | ||
|
||
|
||
def test_sparse_output_multilabel_binarizer(): | ||
|
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 len is the fix, right?
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.
Correct - that's all that was needed to produce a sensible error 😄