Skip to content

[WIP] Prototype 2 for strict check_estimator mode #16890

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

Closed
3 changes: 2 additions & 1 deletion sklearn/decomposition/_sparse_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ def transform(self, X):
return U

def _more_tags(self):
from sklearn.utils.estimator_checks import check_methods_subset_invariance # noqa
return {
'_xfail_checks': {
"check_methods_subset_invariance":
check_methods_subset_invariance:
"fails for the transform method"
}
}
Expand Down
3 changes: 2 additions & 1 deletion sklearn/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,11 @@ def predict_log_proba(self, X):
return [np.log(p) for p in proba]

def _more_tags(self):
from sklearn.utils.estimator_checks import check_methods_subset_invariance # noqa
return {
'poor_score': True, 'no_validation': True,
'_xfail_checks': {
'check_methods_subset_invariance':
check_methods_subset_invariance:
'fails for the predict method'
}
}
Expand Down
3 changes: 2 additions & 1 deletion sklearn/neural_network/_rbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,10 @@ def fit(self, X, y=None):
return self

def _more_tags(self):
from sklearn.utils.estimator_checks import check_methods_subset_invariance # noqa
return {
'_xfail_checks': {
'check_methods_subset_invariance':
check_methods_subset_invariance:
'fails for the decision_function method'
}
}
6 changes: 4 additions & 2 deletions sklearn/svm/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,13 @@ def __init__(self, nu=0.5, kernel='rbf', degree=3, gamma='scale',
random_state=random_state)

def _more_tags(self):
from ..utils.estimator_checks import check_class_weight_classifiers # noqa
from ..utils.estimator_checks import check_methods_subset_invariance # noqa
return {
'_xfail_checks': {
'check_methods_subset_invariance':
check_methods_subset_invariance:
'fails for the decision_function method',
'check_class_weight_classifiers': 'class_weight is ignored.'
check_class_weight_classifiers: 'class_weight is ignored.'
}
}

Expand Down
59 changes: 59 additions & 0 deletions sklearn/tests/test_gonna_be_removed_dont_worry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Should be in test_estimator_checks. Putting this here temporarily because I'm
# too lazy to make it work without pytest.

# import functools
import pytest
from sklearn.linear_model import LogisticRegression
from sklearn.exceptions import SkipTestWarning
from sklearn.utils.estimator_checks import check_estimator
# from sklearn.utils.estimator_checks import some_strict_check
# from sklearn.utils.estimator_checks import some_partially_strict_check


def test_strict_mode(capsys):

est = LogisticRegression()
with pytest.warns(SkipTestWarning, match='strict mode is off'):
check_estimator(est, strict_mode=False)

expected_out = 'in non-strict part of some_partially_strict_check\n'
assert capsys.readouterr().out == expected_out

check_estimator(est, strict_mode=True)
expected_output = (
"in some_strict_check\n"
"in non-strict part of some_partially_strict_check\n"
"in strict part of some_partially_strict_check\n"
)
assert capsys.readouterr().out == expected_output


# class LR1(LogisticRegression):
# def _more_tags(self):
# return {
# '_xfail_checks': {
# some_strict_check: 'whatever reason',
# some_partially_strict_check: 'whatever reason',
# }
# }


# class LR2(LogisticRegression):
# def _more_tags(self):
# return {
# '_xfail_checks': {
# functools.partial(some_strict_check): 'whatever reason',
# functools.partial(some_partially_strict_check): 'whatever reason', # noqa
# }
# }


# @pytest.mark.parametrize('est, expected_output', (
# (LR1(), ""),
# # (LR2(), ""),
# )
# )
# def test_xfail_tag_is_partial_func(est, expected_output, capsys):

# check_estimator(est, strict_mode=True)
# assert capsys.readouterr().out == expected_output
Loading