Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changes/dev/14283.other.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid pytest 10 deprecation warnings when parametrizing scikit-learn estimator checks, by :newcontrib:`Deepesh Sonar`.
1 change: 1 addition & 0 deletions doc/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
.. _David Julien: https://github.com/Swy7ch
.. _David Sabbagh: https://github.com/DavidSabbagh
.. _Deep Kaur: https://github.com/Dpereaptkhamur-13
.. _Deepesh Sonar: https://github.com/Deepnar
.. _Denis Engemann: https://denis-engemann.de
.. _Desislava Petkova: https://github.com/dipetkov
.. _Dev Parikh: https://github.com/devparikh0506
Expand Down
1 change: 0 additions & 1 deletion mne/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def pytest_configure(config: pytest.Config):
# sklearn
ignore:Python binding for RankQuantileOptions.*:RuntimeWarning
ignore:.*The `disp` and `iprint` options of the L-BFGS-B solver.*:DeprecationWarning
ignore:Passing a non-Collection iterable to parametrize[.\n]*:
# matplotlib<->nilearn
ignore:[\S\s]*You are using the 'agg' matplotlib backend[\S\s]*:UserWarning
# matplotlib<->pyparsing
Expand Down
38 changes: 38 additions & 0 deletions mne/decoding/tests/_sklearn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Authors: The MNE-Python contributors.
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

from functools import partial

import pytest
from sklearn.utils.estimator_checks import (
parametrize_with_checks as _sklearn_parametrize_with_checks,
)


# TODO VERSION: Remove once scikit-learn 1.10.0 is the minimum supported version
# scikit-learn/scikit-learn#34448
def _materialize_parametrize_mark(sklearn_decorator, func):
"""Materialize generated argvalues in sklearn's pytest mark."""
marked_func = sklearn_decorator(func)
marks = marked_func.pytestmark
if not isinstance(marks, list):
marks = [marks]
else:
marks = list(marks)
for index, mark in enumerate(marks):
if mark.name == "parametrize":
args = (*mark.args[:1], list(mark.args[1]), *mark.args[2:])
marks[index] = pytest.mark.parametrize(*args, **mark.kwargs).mark
break
marked_func.pytestmark = marks
return marked_func


def _parametrize_with_checks(estimators):
"""Parametrize estimator checks with pytest-compatible argvalues."""
sklearn_decorator = _sklearn_parametrize_with_checks(estimators)
return partial(_materialize_parametrize_mark, sklearn_decorator)


parametrize_with_checks = _parametrize_with_checks
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from sklearn.multiclass import OneVsRestClassifier
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne import EpochsArray, create_info
from mne.decoding import GeneralizingEstimator, Scaler, TransformerMixin, Vectorizer
Expand All @@ -52,6 +51,7 @@
get_coef,
)
from mne.decoding.search_light import SlidingEstimator
from mne.decoding.tests._sklearn import parametrize_with_checks
from mne.utils import check_version


Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_csp.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
from sklearn.model_selection import StratifiedKFold, cross_val_score
from sklearn.pipeline import Pipeline, make_pipeline
from sklearn.svm import SVC
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne import Epochs, compute_proj_raw, io, pick_types, read_events
from mne.decoding import CSP, LinearModel, Scaler, SPoC, get_coef, read_csp, read_spoc
from mne.decoding.csp import _ajd_pham
from mne.decoding.tests._sklearn import parametrize_with_checks
from mne.utils import catch_logging, check_version

data_dir = Path(__file__).parents[2] / "io" / "tests" / "data"
Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_ems.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
pytest.importorskip("sklearn")

from sklearn.model_selection import StratifiedKFold
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne import Epochs, io, pick_types, read_events
from mne.decoding import EMS, compute_ems
from mne.decoding.tests._sklearn import parametrize_with_checks

data_dir = Path(__file__).parents[2] / "io" / "tests" / "data"
raw_fname = data_dir / "test_raw.fif"
Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_ged.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from sklearn.model_selection import ParameterGrid
from sklearn.utils._testing import assert_allclose
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne import Epochs, compute_rank, create_info, pick_types, read_events
from mne._fiff.proj import make_eeg_average_ref_proj
Expand All @@ -29,6 +28,7 @@
)
from mne.decoding._mod_ged import _no_op_mod
from mne.decoding.base import _GEDTransformer
from mne.decoding.tests._sklearn import parametrize_with_checks
from mne.io import read_raw

data_dir = Path(__file__).parents[2] / "io" / "tests" / "data"
Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_receptive_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
pytest.importorskip("sklearn")

from sklearn.linear_model import Ridge
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne.decoding import ReceptiveField, TimeDelayingRidge
from mne.decoding.receptive_field import (
Expand All @@ -22,6 +21,7 @@
_delays_to_slice,
_times_to_delays,
)
from mne.decoding.tests._sklearn import parametrize_with_checks
from mne.decoding.time_delaying_ridge import _compute_corrs, _compute_reg_neighbors

data_dir = Path(__file__).parents[2] / "io" / "tests" / "data"
Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_search_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from sklearn.multiclass import OneVsRestClassifier
from sklearn.pipeline import make_pipeline
from sklearn.svm import SVC
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne.decoding.search_light import GeneralizingEstimator, SlidingEstimator
from mne.decoding.tests._sklearn import parametrize_with_checks
from mne.decoding.transformer import Vectorizer
from mne.utils import check_version, use_log_level

Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_ssd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
pytest.importorskip("sklearn")

from sklearn.pipeline import Pipeline
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne import Epochs, create_info, io, pick_types, read_events
from mne._fiff.pick import _picks_to_idx
from mne.decoding import CSP
from mne.decoding._mod_ged import _get_spectral_ratio
from mne.decoding.ssd import SSD, read_ssd
from mne.decoding.tests._sklearn import parametrize_with_checks
from mne.filter import filter_data
from mne.time_frequency import psd_array_welch

Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_time_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
pytest.importorskip("sklearn")

from sklearn.base import clone
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne.decoding.tests._sklearn import parametrize_with_checks
from mne.decoding.time_frequency import TimeFrequency


Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from sklearn.kernel_ridge import KernelRidge
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne import Epochs, EpochsArray, create_info, io, pick_types, read_events
from mne.decoding import (
Expand All @@ -31,6 +30,7 @@
UnsupervisedSpatialFilter,
Vectorizer,
)
from mne.decoding.tests._sklearn import parametrize_with_checks
from mne.defaults import DEFAULTS
from mne.utils import use_log_level

Expand Down
2 changes: 1 addition & 1 deletion mne/decoding/tests/test_xdawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from numpy.testing import assert_array_almost_equal

pytest.importorskip("sklearn")
from sklearn.utils.estimator_checks import parametrize_with_checks

from mne.decoding import XdawnTransformer, read_xdawn_transformer
from mne.decoding.tests._sklearn import parametrize_with_checks


@pytest.mark.filterwarnings("ignore:.*Only one sample available.*")
Expand Down
Loading