-
-
Notifications
You must be signed in to change notification settings - Fork 26k
MAINT Make param validation more lenient towards downstream dependencies #25088
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
MAINT Make param validation more lenient towards downstream dependencies #25088
Conversation
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 and I like the reasoning.
Worth adding a test that makes sure this behaviour works also in the future?
An alternative could be to check if the estimator that is being checked lives inside the |
Yes that's a good idea. Done |
This is the current behavior. scikit-learn/sklearn/tests/test_common.py Lines 460 to 466 in 04f3298
|
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.
Minor comment, otherwise LGTM
# does not raise, niether because "b" is not in the constraints dict, neither | ||
# because "a" is not a parameter of the estimator. |
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.
Nit: I think this is a little easier to parse:
# does not raise, niether because "b" is not in the constraints dict, neither | |
# because "a" is not a parameter of the estimator. | |
# does not raise, even tho "b" is not in the constraints dict and | |
# "a" is not a parameter of the estimator. |
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.
Alternatively:
# does not raise, niether because "b" is not in the constraints dict, neither | |
# because "a" is not a parameter of the estimator. | |
# Does not raise an error, despite the fact that: | |
# 1) "a" is not a parameter of the estimator | |
# 2) "b" is not present in the constraints dict |
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 pending some wording update on the inline comment
I'm confused. Why do we need this change then? This PR changes My "alternative proposal" idea was to add logic to |
Merging with 3 approvals, thanks |
Currently
validate_params
checks that all entries in the constraints dict are actual parameters of the class. It can break third party estimators (it was actually catched trying imbalanced-learn with the 1.2.0rc1). For instance if someone does:then it would raise an error because "algorithm" is in the constraint dict or the base class but not a param of the new class.
I think we should not enforce that for third party estimators. For scikit-learn estimators we do want to enforce it but we already check that we have a 1 to 1 matching in the common tests:
scikit-learn/sklearn/utils/estimator_checks.py
Lines 4047 to 4055 in 2b34dfd
cc/ @glemaitre