Skip to content

Fix #31077: Improve error when categorical_features is an empty list - #31146

Merged
jeremiedbb merged 5 commits into
scikit-learn:mainfrom
pedroL0pes:fix_31077
Apr 21, 2025
Merged

Fix #31077: Improve error when categorical_features is an empty list#31146
jeremiedbb merged 5 commits into
scikit-learn:mainfrom
pedroL0pes:fix_31077

Conversation

@pedroL0pes

Copy link
Copy Markdown
Contributor

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.

Reference Issues/PRs

Fixes #31077

What does this implement/fix? Explain your changes.

List of changes:

  • Added an explicit check for empty lists in categorical_features.
  • A clearer ValueError is now displayed when categorical_features is an empty list, informing users to use None instead.
  • Added a test case to ensure proper exception handling.

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.

… 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>
@github-actions

github-actions Bot commented Apr 3, 2025

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 17b19a2. Link to the linter CI: here

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I directly pushed some small modifications. LGTM, Thanks !

@jeremiedbb
jeremiedbb merged commit af7df5c into scikit-learn:main Apr 21, 2025
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Partial dependence broken when categorical_features has an empty list

2 participants