Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MNT Param validation: do not expose internal values in error msg #23459

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

Conversation

jeremiedbb
Copy link
Member

We have valid values for parameters that are for internal purpose (e.g. "warn" or "deprecated") and I don't think we should expose them in the error message raised by the param validation.

for instance we currently have (since we merged #23038)

>>> KMeans(n_init="bad").fit(None)
ValueError: The 'n_init' parameter of KMeans must be a str among {'auto', 'warn'} or an int in the range [1, inf). Got 'bad' instead.

With this PR, the message becomes

ValueError: The 'n_init' parameter of KMeans must be a str among {'auto'} or an int in the range [1, inf). Got 'bad' instead.

Also, suppose you have a param that only accepts integers. If we deprecate it, it will accept the string "deprecated". I don't think we want the error message to mention that a str is a valid type at all.

I propose to add a param internal to StrOptions such that values that are listed in internal won't be exposed and if all options are internal options, even the fact that a str is valid is not exposed.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

This makes sense. LGTM

Copy link
Member

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @jeremiedbb.

I just have one remark.

@jjerphan jjerphan merged commit 122876e into scikit-learn:main May 31, 2022
ogrisel pushed a commit to ogrisel/scikit-learn that referenced this pull request Jul 11, 2022
…kit-learn#23459)

* allow to not expose internal valid params in error msg

* ensure deprecated and internal do not overlap

* deprecated and internal must be subsets of options

* black
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.

3 participants