8000 MAINT remove _named_check (#10160) · scikit-learn/scikit-learn@a13a7d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a13a7d8

Browse files
lesteveamueller
authored andcommitted
MAINT remove _named_check (#10160)
which was a nose-specific thing to have good names for tests using yield
1 parent 47cf43d commit a13a7d8

File tree

3 files changed

+21
-51
lines changed

3 files changed

+21
-51
lines changed

sklearn/metrics/tests/test_common.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from sklearn.utils.testing import assert_raise_message
2424
from sklearn.utils.testing import assert_true
2525
from sklearn.utils.testing import ignore_warnings
26-
from sklearn.utils.testing import _named_check
2726

2827
from sklearn.metrics import accuracy_score
2928
from sklearn.metrics import balanced_accuracy_score
@@ -895,8 +894,8 @@ def test_averaging_multiclass(n_samples=50, n_classes=3):
895894
y_pred_binarize = lb.transform(y_pred)
896895

897896
for name in METRICS_WITH_AVERAGING:
898-
yield (_named_check(check_averaging, name), name, y_true,
899-
y_true_binarize, y_pred, y_pred_binarize, y_score)
897+
yield (check_averaging, name, y_true, y_true_binarize,
898+
y_pred, y_pred_binarize, y_score)
900899

901900

902901
def test_averaging_multilabel(n_classes=5, n_samples=40):
@@ -910,8 +909,8 @@ def test_averaging_multilabel(n_classes=5, n_samples=40):
910909
y_pred_binarize = y_pred
911910

912911
for name in METRICS_WITH_AVERAGING + THRESHOLDED_METRICS_WITH_AVERAGING:
913-
yield (_named_check(check_averaging, name), name, y_true,
914-
y_true_binarize, y_pred, y_pred_binarize, y_score)
912+
yield (check_averaging, name, y_true, y_true_binarize,
913+
y_pred, y_pred_binarize, y_score)
915914

916915

917916
def test_averaging_multilabel_all_zeroes():
@@ -922,8 +921,8 @@ def test_averaging_multilabel_all_zeroes():
922921
y_pred_binarize = y_pred
923922

924923
for name in METRICS_WITH_AVERAGING:
925-
yield (_named_check(check_averaging, name), name, y_true,
926-
y_true_binarize, y_pred, y_pred_binarize, y_score)
924+
yield (check_averaging, name, y_true, y_true_binarize,
925+
y_pred, y_pred_binarize, y_score)
927926

928927
# Test _average_binary_score for weight.sum() == 0
929928
binary_metric = (lambda y_true, y_score, average="macro":
@@ -941,8 +940,8 @@ def test_averaging_multilabel_all_ones():
941940
y_pred_binarize = y_pred
942941

943942
for name in METRICS_WITH_AVERAGING:
944-
yield (_named_check(check_averaging, name), name, y_true,
945-
y_true_binarize, y_pred, y_pred_binarize, y_score)
943+
yield (check_averaging, name, y_true, y_true_binarize,
944+
y_pred, y_pred_binarize, y_score)
946945

947946

948947
@ignore_warnings
@@ -1031,8 +1030,7 @@ def test_sample_weight_invariance(n_samples=50):
10311030
if name in METRICS_WITHOUT_SAMPLE_WEIGHT:
10321031
continue
10331032
metric = ALL_METRICS[name]
1034-
yield _named_check(check_sample_weight_invariance, name), name,\
1035-
metric, y_true, y_pred
1033+
yield check_sample_weight_invariance, name, metric, y_true, y_pred
10361034

10371035
# binary
10381036
random_state = check_random_state(0)
@@ -1047,11 +1045,9 @@ def test_sample_weight_invariance(n_samples=50):
10471045
continue
10481046
metric = ALL_METRICS[name]
10491047
if name in THRESHOLDED_METRICS:
1050-
yield _named_check(check_sample_weight_invariance, name), name,\
1051-
metric, y_true, y_score
1048+
yield check_sample_weight_invariance, name, metric, y_true, y_score
10521049
else:
1053-
yield _named_check(check_sample_weight_invariance, name), name,\
1054-
metric, y_true, y_pred
1050+
yield check_sample_weight_invariance, name, metric, y_true, y_pred
10551051

10561052
# multiclass
10571053
random_state = check_random_state(0)
@@ -1066,11 +1062,9 @@ def test_sample_weight_invariance(n_samples=50):
10661062
continue
10671063
metric = ALL_METRICS[name]
10681064
if name in THRESHOLDED_METRICS:
1069-
yield _named_check(check_sample_weight_invariance, name), name,\
1070-
metric, y_true, y_score
1065+
yield check_sample_weight_invariance, name, metric, y_true, y_score
10711066
else:
1072-
yield _named_check(check_sample_weight_invariance, name), name,\
1073-
metric, y_true, y_pred
1067+
yield check_sample_weight_invariance, name, metric, y_true, y_pred
10741068

10751069
# multilabel indicator
10761070
_, ya = make_multilabel_classification(n_features=1, n_classes=20,
@@ -1090,11 +1084,11 @@ def test_sample_weight_invariance(n_samples=50):
10901084

10911085
metric = ALL_METRICS[name]
10921086
if name in THRESHOLDED_METRICS:
1093-
yield (_named_check(check_sample_weight_invariance, name), name,
1094-
metric, y_true, y_score)
1087+
yield (check_sample_weight_invariance, name, metric,
1088+
y_true, y_score)
10951089
else:
1096-
yield (_named_check(check_sample_weight_invariance, name), name,
1097-
metric, y_true, y_pred)
1090+
yield (check_sample_weight_invariance, name, metric,
1091+
y_true, y_pred)
10981092

10991093

11001094
@ignore_warnings

sklearn/tests/test_common.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from sklearn.utils.testing import assert_greater
2121
from sklearn.utils.testing import assert_in
2222
from sklearn.utils.testing import ignore_warnings
23-
from sklearn.utils.testing import _named_check
2423

2524
import sklearn
2625
from sklearn.cluster.bicluster import BiclusterMixin
@@ -53,8 +52,7 @@ def test_all_estimators():
5352

5453
for name, Estimator in estimators:
5554
# some can just not be sensibly default constructed
56-
yield (_named_check(check_parameters_default_constructible, name),
57-
name, Estimator)
55+
yield check_parameters_default_constructible, name, Estimator
5856

5957

6058
def test_non_meta_estimators():
@@ -67,12 +65,11 @@ def test_non_meta_estimators():
6765
continue
6866
estimator = Estimator()
6967
# check this on class
70-
yield _named_check(
71-
check_no_fit_attributes_set_in_init, name), name, Estimator
68+
yield check_no_fit_attributes_set_in_init, name, Estimator
7269

7370
for check in _yield_all_checks(name, estimator):
7471
set_checking_parameters(estimator)
75-
yield _named_check(check, name), name, estimator
72+
yield check, name, estimator
7673

7774

7875
def test_configure():
@@ -114,8 +111,7 @@ def test_class_weight_balanced_linear_classifiers():
114111
issubclass(clazz, LinearClassifierMixin))]
115112

116113
for name, Classifier in linear_classifiers:
117-
yield _named_check(check_class_weight_balanced_linear_classifier,
118-
name), name, Classifier
114+
yield check_class_weight_balanced_linear_classifier, name, Classifier
119115

120116

121117
@ignore_warnings

sklearn/utils/testing.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -753,26 +753,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
753753
_delete_folder(self.temp_folder)
754754

755755

756-
class _named_check(object):
757-
"""Wraps a check to show a useful description
758-
759-
Parameters
760-
----------
761-
check : function
762-
Must have ``__name__`` and ``__call__``
763-
arg_text : str
764-
A summary of arguments to the check
765-
"""
766-
# Setting the description on the function itself can give incorrect results
767-
# in failing tests
768-
def __init__(self, check, arg_text):
769-
self.check = check
770-
self.description = ("{0[1]}.{0[3]}:{1.__name__}({2})".format(
771-
inspect.stack()[1], check, arg_text))
772-
773-
def __call__(self, *args, **kwargs):
774-
return self.check(*args, **kwargs)
775-
776756
# Utils to test docstrings
777757

778758

0 commit comments

Comments
 (0)
0