-
-
Notifications
You must be signed in to change notification settings - Fork 26k
MNT Param validation: Make it possible to mark a constraint as hidden #23558
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
MNT Param validation: Make it possible to mark a constraint as hidden #23558
Conversation
sklearn/linear_model/_base.py
Outdated
@@ -640,7 +640,7 @@ class LinearRegression(MultiOutputMixin, RegressorMixin, LinearModel): | |||
|
|||
_parameter_constraints = { | |||
"fit_intercept": [bool], | |||
"normalize": [StrOptions({"deprecated"}, internal={"deprecated"}), bool], | |||
"normalize": [Internal(StrOptions({"deprecated"})), bool], |
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.
For developer ergonomics, Internal
looks very similar to Interval
. (At a glance, I thought it was Interval
). What do you think of renaming Interval
to Range
?
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 kind of prefer Interval
, and range
being a python keyword I think it could also bring confusion. Maybe we can change Internal
instead. What do you think about Private
or Hidden
?
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 am +1 for Hidden
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 am fine with the rest of the PR.
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
@@ -273,7 +274,8 @@ def _tolerance(X, tol): | |||
"sample_weight": ["array-like", None], | |||
"init": [StrOptions({"k-means++", "random"}), callable, "array-like"], | |||
"n_init": [ | |||
StrOptions({"auto", "warn"}, internal={"warn"}), | |||
StrOptions({"auto"}), | |||
Hidden(StrOptions({"warn"})), |
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.
The alternative is StrOptions({"warn"}, hidden=True)
, but then we would need _InstancesOf
"public", to do InstancesOf(Criterion, hidden=True)
. Also all the other constraints will have to be "public" to be configured to hide.
With that in mind, I'm okay with the PR as is.
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
@glemaitre This PR changed a little bit since your approval. Do you want to take another look?
Still LGTM. Merging. |
Some parameters accepts types as an unofficial way. For instance
criterion
in trees can be an instance ofCriterion
but that's not documented and not meant to be documented.For these, we don't want the error message of the validation of this parameter to say that this unofficial type is valid. Hence this PR proposes to make it possible to mark a constraint as
internal
such that it's not shown in the message.