Fix #31077: Improve error when categorical_features is an empty list - #31146
Merged
Conversation
… empty list Passing an empty list to `categorical_features` in `partial_dependence` was causing a ValueError with an unclear message. Now, we explicitly check for this case and raise a clearer ValueError instructing users to use `None` instead. Added a test case to ensure proper exception handling. Signed-off-by: Pedro Lopes <pedro.m.a.r.lopes@tecnico.ulisboa.pt>
Signed-off-by: Pedro Lopes <pedro.m.a.r.lopes@tecnico.ulisboa.pt>
jeremiedbb
approved these changes
Apr 21, 2025
jeremiedbb
left a comment
Member
There was a problem hiding this comment.
I directly pushed some small modifications. LGTM, Thanks !
lucyleeow
pushed a commit
to EmilyXinyi/scikit-learn
that referenced
this pull request
Apr 23, 2025
…learn#31146) Signed-off-by: Pedro Lopes <pedro.m.a.r.lopes@tecnico.ulisboa.pt> Co-authored-by: Jérémie du Boisberranger <jeremie@probabl.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Passing an empty list to
categorical_featuresinpartial_dependencewas causing a ValueError with an unclear message. Now, we explicitly check for this case and raise a clearer ValueError instructing users to useNoneinstead. Added a test case toensure proper exception handling.
Reference Issues/PRs
Fixes #31077
What does this implement/fix? Explain your changes.
List of changes:
categorical_features.ValueErroris now displayed whencategorical_featuresis an empty list, informing users to useNoneinstead.Any other comments?
This is a minor fix which improves usability by preventing confusion. Let me know if any additional tests or changes are required.