(name, classifier_orig)
| 2918 | |
| 2919 | @ignore_warnings(category=FutureWarning) |
| 2920 | def check_classifiers_one_label(name, classifier_orig): |
| 2921 | error_string_fit = "Classifier can't train when only one class is present." |
| 2922 | error_string_predict = "Classifier can't predict when only one class is present." |
| 2923 | classifier = clone(classifier_orig) |
| 2924 | rnd = np.random.RandomState(0) |
| 2925 | X_train = rnd.uniform(size=(10, 3)) |
| 2926 | X_test = rnd.uniform(size=(10, 3)) |
| 2927 | X_train, X_test = _enforce_estimator_tags_X(classifier, X_train, X_test=X_test) |
| 2928 | y = np.ones(10) |
| 2929 | # catch deprecation warnings |
| 2930 | with ignore_warnings(category=FutureWarning): |
| 2931 | with raises( |
| 2932 | ValueError, match="class", may_pass=True, err_msg=error_string_fit |
| 2933 | ) as cm: |
| 2934 | classifier.fit(X_train, y) |
| 2935 | |
| 2936 | if cm.raised_and_matched: |
| 2937 | # ValueError was raised with proper error message |
| 2938 | return |
| 2939 | |
| 2940 | assert_array_equal(classifier.predict(X_test), y, err_msg=error_string_predict) |
| 2941 | |
| 2942 | |
| 2943 | @ignore_warnings(category=FutureWarning) |
nothing calls this directly
no test coverage detected
searching dependent graphs…