Skip to content
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

[FIX] Change error string to match scikit-learn InvalidParameterError message #3763

Merged
merged 2 commits into from
Jun 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions nilearn/decoding/tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import numpy as np
import pytest
import sklearn
from numpy.testing import assert_array_almost_equal
from sklearn.datasets import load_iris, make_classification, make_regression
from sklearn.dummy import DummyClassifier, DummyRegressor
Expand All @@ -43,6 +44,7 @@
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVR, LinearSVC

from nilearn._utils import _compare_version
from nilearn._utils.param_validation import check_feature_screening
from nilearn.decoding.decoder import (
Decoder,
Expand Down Expand Up @@ -681,8 +683,18 @@ def test_decoder_error_unknown_scoring_metrics(

model = Decoder(estimator=dummy_classifier, mask=mask, scoring="foo")

with pytest.raises(ValueError, match="'foo' is not a valid scoring value"):
model.fit(X, y)
if _compare_version(sklearn.__version__, ">", "1.2.2"):
with pytest.raises(
ValueError,
match="The 'scoring' parameter of check_scoring "
"must be a str among",
):
model.fit(X, y)
else:
with pytest.raises(
ValueError, match="'foo' is not a valid scoring value"
):
model.fit(X, y)


def test_decoder_dummy_classifier_default_scoring():
Expand Down