-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
ENH added consistency checks for args of check_scalar function #22027
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
Conversation
Some checks are not successful but I don't understand the error messages. |
sklearn/utils/validation.py
Outdated
|
||
if min_val is None and include_boundaries in ("left"): | ||
raise ValueError( | ||
"`include_boundaries`='left' with no `min_val` is inconsistent." |
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.
"`include_boundaries`='left' with no `min_val` is inconsistent." | |
"`include_boundaries`='left' without specifying explicitly `min_val` is inconsistent." |
sklearn/utils/validation.py
Outdated
@@ -1418,6 +1419,16 @@ def check_scalar( | |||
f"Possible values are: {expected_include_boundaries}." | |||
) | |||
|
|||
if max_val is None and include_boundaries in ("right"): | |||
raise ValueError( | |||
"`include_boundaries`='right' with no `max_val` is inconsistent." |
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.
"`include_boundaries`='right' with no `max_val` is inconsistent." | |
"`include_boundaries`='right' without specifying explicitly `max_val` is inconsistent." |
Thank you for your replies, |
@glemaitre, could you take a look? |
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.
Please add an entry to the change log at doc/whats_new/v1.1.rst
. Like the other entries there, please reference this pull request with :pr:
and credit yourself (and other contributors if applicable) with :user:
.
sklearn/utils/validation.py
Outdated
@@ -1418,6 +1419,18 @@ def check_scalar( | |||
f"Possible values are: {expected_include_boundaries}." | |||
) | |||
|
|||
if max_val is None and include_boundaries in ("right"): |
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 assume that here we want to check for both possibilities.
if max_val is None and include_boundaries in ("right"): | |
if max_val is None and include_boundaries in ("right", "both"): |
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.
Then we need to do:
if max_val is None and include_boundaries in ("right"): | |
if max_val is None and include_boundaries == "right": |
sklearn/utils/validation.py
Outdated
"is inconsistent." | ||
) | ||
|
||
if min_val is None and include_boundaries in ("left"): |
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 same here.
if min_val is None and include_boundaries in ("left"): | |
if min_val is None and include_boundaries in ("left", "both"): |
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.
if min_val is None and include_boundaries in ("left"): | |
if min_val is None and include_boundaries == "left": |
int, | ||
2, | ||
None, | ||
"right", |
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.
We should add the case where we also have "both"
once it is included in the check below.
I found that writing "if min_val is None and include_boundaries in ("left", "both"):" obliges the user to specify 'include_boundary' every time only one boundary is defined, because "both" is the default value. This would be equivalent to removing the default value of this parameter. What's more, it raises dozens of errors in the existing code. Therefore, I don't think it is the behavior we want. This is what I reverted to the previous writing (and only updated the changelog). |
This is a bit annoying but we need |
sklearn/utils/validation.py
Outdated
@@ -1418,6 +1419,18 @@ def check_scalar( | |||
f"Possible values are: {expected_include_boundaries}." | |||
) | |||
|
|||
if max_val is None and include_boundaries in ("right"): |
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.
Then we need to do:
if max_val is None and include_boundaries in ("right"): | |
if max_val is None and include_boundaries == "right": |
sklearn/utils/validation.py
Outdated
"is inconsistent." | ||
) | ||
|
||
if min_val is None and include_boundaries in ("left"): |
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.
if min_val is None and include_boundaries in ("left"): | |
if min_val is None and include_boundaries == "left": |
doc/whats_new/v1.1.rst
Outdated
- |Enhancement| :func:`check_scalar` raises new errors when inconsistent | ||
boundaries are entered (e.g. `include_boundaries`='left' without | ||
specifying explicitly `min_val`). | ||
:pr:`22027` by `Marie Lanternier <mlant>`. |
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.
- |Enhancement| :func:`check_scalar` raises new errors when inconsistent | |
boundaries are entered (e.g. `include_boundaries`='left' without | |
specifying explicitly `min_val`). | |
:pr:`22027` by `Marie Lanternier <mlant>`. | |
- |Fix| :func:`check_scalar` raises an error when `include_boundaries={"left", "right"}` | |
and the boundaries are not set. | |
:pr:`22027` by `Marie Lanternier <mlant>`. |
raise ValueError( | ||
"`include_boundaries`='left' " | ||
"without specifying explicitly `min_val` " | ||
"is inconsistent." |
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.
Could you wrap the error message on 2 lines only and take profit of the 88 characters width.
raise ValueError( | ||
"`include_boundaries`='right' " | ||
"without specifying explicitly `max_val` " | ||
"is inconsistent." |
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.
Could you wrap the error message on 2 lines only and take profit of the 88 characters width.
@glemaitre I have fixed a few typos. Now everything LGTM and is ready for review. |
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. Maybe @thomasjpfan wants to have a look.
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
scikit-learn#22027)" This reverts commit 1e4ac04.
Added two checks on the args
val_min
,val_max
andinclude_boudaries
of the function check_scalar #21948:Here is the new output of @sply88 short script :
1: include_boundaries=left -> x=1, min_val=1: pass
2: include_boundaries=left -> x=1, max_val=1: ValueError("
include_boundaries
='left' with nomin_val
is inconsistent.")3: include_boundaries=right -> x=1, min_val=1: ValueError("
include_boundaries
='right' with nomax_val
is inconsistent.")4: include_boundaries=right -> x=1, max_val=1: pass
5: include_boundaries=both -> x=1, min_val=1: pass
6: include_boundaries=both -> x=1, max_val=1: pass
7: include_boundaries=neither -> x=1, min_val=1: ValueError('input == 1, must be > 1.')
8: include_boundaries=neither -> x=1, max_val=1: ValueError('input == 1, must be < 1.')