FIX Change error message of check_X_y when y is None - #22578
Conversation
thomasjpfan
left a comment
There was a problem hiding this comment.
Thank you for the PR! Can you add a non-regression test to sklearn/utils/tests/test_estimator_checks.py that contains your snippet from #22576 and assert no warning is raised?
An example of checking for no warnings is here:
scikit-learn/sklearn/utils/tests/test_estimator_checks.py
Lines 991 to 994 in c36f926
| """ | ||
| if y is None: | ||
| raise ValueError("y cannot be None") | ||
| raise ValueError("Expected array-like (array or non-string sequence), got None") |
There was a problem hiding this comment.
I think including y in the error message is more informative. To pass the check we can do:
if y is None:
if estimator is None:
estimator_name = "estimator"
else:
estimator_name = _check_estimator_name(estimator)
raise ValueError(
f"{estimator_name} requires y to be passed, but the target y is None"
)There was a problem hiding this comment.
I agree, I changed the value error accordingly to your suggestion. Thanks!
| - |Fix| Changes the error message of the ValidationError raised by | ||
| :func:`utils.validation.check_X_y` when y is None so that it is compatible | ||
| with :func:`utils.estimator_checks.check_requires_y_none`. :pr:`22578` by | ||
| :user:`Claudio Salvatore Arcidiacono <ClaudioSalvatoreArcidiacono>`. |
There was a problem hiding this comment.
Can we move this into doc/whats_new/v1.1.rst ?
There was a problem hiding this comment.
Sure, it should have been moved now :)
This test ensures consistency between the error returned by the check_X_y function and the response that is checked by the check_requires_y_none function
Thanks for your suggestion. I have added an extra test to |
thomasjpfan
left a comment
There was a problem hiding this comment.
Small nit, otherwise LGTM
Co-authored-by: Thomas J. Fan <[email protected]>
) Co-authored-by: Thomas J. Fan <[email protected]> Co-authored-by: claudio.arcidiacono <[email protected]> Co-authored-by: Julien Jerphanion <[email protected]>
Reference Issues/PRs
Fixes #22576
What does this implement/fix? Explain your changes.
Changes the error message of the
ValidationErrorthat is raised bycheck_X_ywhen y is None from:to
Any other comments?