Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX Change error message of check_X_y when y is None - #22578

Merged
thomasjpfan merged 12 commits into
scikit-learn:mainfrom
ClaudioSalvatoreArcidiacono:22576_change_error_message_check_X_y_when_y_is_None
Mar 7, 2022
Merged

FIX Change error message of check_X_y when y is None#22578
thomasjpfan merged 12 commits into
scikit-learn:mainfrom
ClaudioSalvatoreArcidiacono:22576_change_error_message_check_X_y_when_y_is_None

Conversation

@ClaudioSalvatoreArcidiacono

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #22576

What does this implement/fix? Explain your changes.

Changes the error message of the ValidationError that is raised by check_X_y when y is None from:

y cannot be None

to

Expected array-like (array or non-string sequence), got None

Any other comments?

@ClaudioSalvatoreArcidiacono ClaudioSalvatoreArcidiacono changed the title Change error message and tests Change error message of check_X_y when y is None Feb 22, 2022
claudio.arcidiacono added 2 commits February 22, 2022 13:28

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

with warnings.catch_warnings(record=True) as record:
estimators = all_estimators()
# no warnings are raised
assert not record

Comment thread sklearn/utils/validation.py Outdated
"""
if y is None:
raise ValueError("y cannot be None")
raise ValueError("Expected array-like (array or non-string sequence), got None")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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"
        )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree, I changed the value error accordingly to your suggestion. Thanks!

Comment thread doc/whats_new/v1.0.rst Outdated
Comment on lines +143 to +146
- |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>`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we move this into doc/whats_new/v1.1.rst ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, it should have been moved now :)

claudio.arcidiacono added 4 commits February 22, 2022 17:23
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
@ClaudioSalvatoreArcidiacono

Copy link
Copy Markdown
Contributor Author

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:

with warnings.catch_warnings(record=True) as record:
estimators = all_estimators()
# no warnings are raised
assert not record

Thanks for your suggestion. I have added an extra test to sklearn/utils/tests/test_estimator_checks.py.

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small nit, otherwise LGTM

Comment thread sklearn/utils/tests/test_estimator_checks.py Outdated
@thomasjpfan thomasjpfan added the Quick Review For PRs that are quick to review label Feb 22, 2022
@thomasjpfan thomasjpfan changed the title Change error message of check_X_y when y is None FIX Change error message of check_X_y when y is None Feb 22, 2022
Comment thread doc/whats_new/v1.1.rst Outdated
@thomasjpfan
thomasjpfan merged commit 7a9677e into scikit-learn:main Mar 7, 2022
@ClaudioSalvatoreArcidiacono
ClaudioSalvatoreArcidiacono deleted the 22576_change_error_message_check_X_y_when_y_is_None branch March 8, 2022 08:08
thomasjpfan added a commit to thomasjpfan/scikit-learn that referenced this pull request Mar 8, 2022
)

Co-authored-by: Thomas J. Fan <[email protected]>
Co-authored-by: claudio.arcidiacono <[email protected]>
Co-authored-by: Julien Jerphanion <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:utils Quick Review For PRs that are quick to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent behaviour between check_X_y and check_requires_y_none

3 participants