8000 BUG: error message raised by validate_params cannot pass check_estimator · Issue #33135 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

BUG: error message raised by validate_params cannot pass check_estimator #33135

@MatthewSZhang

Description

@MatthewSZhang

Describe the bug

I maintain the scikit-learn compatible projects fastcan and use check_estimator to check its compatibility.

When I use sklearn.utils.column_or_1d to validate the argument y of fit, the error message of None input is accepted by check_estimator.
However, when I use sklearn.utils._param_validation.validate_params, the error message of None input is invalid for check_estimator.

Both column_or_1d and validate_params are standard ways to validate the function arguments. The error messages of both should be valid.

Steps/Code to Reproduce

from sklearn.utils import column_or_1d
from sklearn.utils._param_validation import validate_params
from sklearn.utils.estimator_checks import check_requires_y_none
from sklearn.base import BaseEstimator

class ClassA(BaseEstimator):
    @validate_params(
        {
            "X": ["array-like"],
            "y": ["array-like"],
        },
        prefer_skip_nested_validation=True,
    )
    def fit(self, X, y):
        return self

class ClassB(BaseEstimator):
    @validate_params(
        {
            "X": ["array-like"],
        },
        prefer_skip_nested_validation=True,
    )
    def fit(self, X, y):
        column_or_1d(y)
        return self


A = ClassA()
B = ClassB()

Expected Results

check_requires_y_none("ClassA", A) # Pass
check_requires_y_none("ClassA", B) # Pass

Actual Results

check_requires_y_none("ClassA", A) # Fail
check_requires_y_none("ClassA", B) # Pass

Versions

sklearn: 1.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0