Skip to content

MNT Param validation: convenience constraint for booleans #23618

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
merged 1 commit into from
Jun 15, 2022

Conversation

jeremiedbb
Copy link
Member

@jeremiedbb jeremiedbb commented Jun 14, 2022

Already merged and currently under reviews PRs for #23462 define the constraints for boolean params as [bool]. The issue is that it's not backward compatible since we usually also accept np.bool_ and even an int.
(Issue raised in this comment #23593 (comment))

Accpeting an int doesn't seem necessary and I propose to deprecate it. Accepting a np.bool_ is probably convenient for many users. To avoid having to repeat all accepted options all the time I propose to make a helper for that and just specify ["boolean"] instead.

Question: Should the docstrings mention bool or np.bool_ or boolean instead of just bool ?

@Nwanna-Joseph
Copy link
Contributor

Nwanna-Joseph commented Jun 15, 2022

@jeremiedbb , This looks nice. Is it possible to leave the [bool] constraint as it is?

In a way, np.bool_ is to bool what Integer is to int. Same thing, different abstractions.

if I use [np.bool_] , then np.bool_ and bool conditions are considered.

If I use [bool], then only bool is considered.

If I use an [int], then bool, np.bool_ and int are considered.

Then it's easy to decouple the use of np.bool_ from bool. For strict backwards compatibility, [np.bool_] would be advised,
for laxed compatibility, [bool] can be used. Just a suggestion.

@glemaitre
Copy link
Member

@Nwanna-Joseph You can always be specific with the specific type. In scikit-learn, we have been too flexible and we need to remain backwards compatible and create a boolean that could allow us to make a proper deprecation cycle in the future.

Copy link
Member

@glemaitre glemaitre left a comment

Choose a reason for hiding this comment

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

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

@jjerphan jjerphan merged commit a657465 into scikit-learn:main Jun 15, 2022
@Nwanna-Joseph
Copy link
Contributor

@Nwanna-Joseph You can always be specific with the specific type. In scikit-learn, we have been too flexible and we need to remain backwards compatible and create a boolean that could allow us to make a proper deprecation cycle in the future.

Oh, I see. Thanks a lot.

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.

4 participants