Skip to content

Commit

Permalink
properly deprecate and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
sappelhoff committed Oct 24, 2024
1 parent 5fcb302 commit cd1e2f2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
34 changes: 27 additions & 7 deletions mne/datasets/eegbci/eegbci.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from os import path as op
from pathlib import Path

from ...utils import _url_to_local_path, logger, verbose
from ...utils import _url_to_local_path, logger, verbose, warn
from ..utils import _do_path_update, _downloader_params, _get_path, _log_time_size

EEGMI_URL = "https://physionet.org/files/eegmmidb/1.0.0/"
Expand Down Expand Up @@ -94,9 +94,10 @@ def data_path(url, path=None, force_update=False, update_path=None, *, verbose=N

@verbose
def load_data(
subjects,
runs,
subjects=None,
runs=None,
*,
subject=None,
path=None,
force_update=False,
update_path=None,
Expand All @@ -116,6 +117,9 @@ def load_data(
The subjects to use. Can be in the range of 1-109 (inclusive).
runs : int | list of int
The runs to use (see Notes for details).
subject : int
This parameter is deprecated and will be removed in mne version 1.9.
Please use ``subjects`` instead.
path : None | path-like
Location of where to look for the EEGBCI data. If ``None``, the environment
variable or config parameter ``MNE_DATASETS_EEGBCI_PATH`` is used. If neither
Expand Down Expand Up @@ -154,18 +158,34 @@ def load_data(
For example, one could do::
>>> from mne.datasets import eegbci
>>> eegbci.load_data(1, [6, 10, 14], "~/datasets") # doctest:+SKIP
>>> eegbci.load_data([1, 2], [6, 10, 14], "~/datasets") # doctest:+SKIP
This would download runs 6, 10, and 14 (hand/foot motor imagery) runs from subject 1
in the EEGBCI dataset to "~/datasets" and prompt the user to store this path in the
config (if it does not already exist).
This would download runs 6, 10, and 14 (hand/foot motor imagery) runs from subjects
1 and 2 in the EEGBCI dataset to "~/datasets" and prompt the user to store this path
in the config (if it does not already exist).
References
----------
.. footbibliography::
"""
import pooch

# XXX: Remove this with mne 1.9 ↓↓↓
# Also remove the subject parameter at that point.
# Also remove the `None` default for subjects and runs params at that point.
if subject is not None:
subjects = subject
warn(
"The ``subject`` parameter is deprecated and will be removed in version "
"1.9. Use the ``subjects`` parameter (note the `s`) to suppress this "
"warning.",
DeprecationWarning,
)
del subject
if subjects is None or runs is None:
raise ValueError("You must pass the parameters ``subjects`` and ``runs``.")
# ↑↑↑

t0 = time.time()

if not hasattr(subjects, "__iter__"):
Expand Down
18 changes: 16 additions & 2 deletions mne/datasets/eegbci/tests/test_eegbci.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.

import pytest

from mne.datasets import eegbci


def test_eegbci_download(tmp_path, fake_retrieve):
"""Test Sleep Physionet URL handling."""
for subj in range(4):
fnames = eegbci.load_data(subj + 1, runs=[3], path=tmp_path, update_path=False)
subjects = range(1, 5)
for subj in subjects:
fnames = eegbci.load_data(subj, runs=[3], path=tmp_path, update_path=False)
assert len(fnames) == 1, subj
assert fake_retrieve.call_count == 4

# XXX: remove in version 1.9
with pytest.warns(DeprecationWarning, match="The ``subject``"):
fnames = eegbci.load_data(
subject=subjects, runs=[3], path=tmp_path, update_path=False
)
assert len(fnames) == 4

# XXX: remove in version 1.9
with pytest.raises(ValueError, match="You must pass the parameters"):
fnames = eegbci.load_data(path=tmp_path, update_path=False)

0 comments on commit cd1e2f2

Please sign in to comment.