Skip to content

Commit

Permalink
deprecate [] as indicating all channels
Browse files Browse the repository at this point in the history
  • Loading branch information
drammock committed Sep 19, 2024
1 parent 3c08d31 commit cb32a98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
5 changes: 3 additions & 2 deletions mne_bids/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ def test_mark_channels(
# Mark `existing_ch_names` as bad in raw and sidecar TSV before we
# begin our actual tests, which should then add additional channels
# to the list of bads, retaining the ones we're specifying here.
mark_channels(ch_names=[], bids_path=bids_path, status="good", verbose=False)
mark_channels(ch_names="all", bids_path=bids_path, status="good", verbose=False)
_bids_validate(bids_root)
raw = read_raw_bids(bids_path=bids_path, verbose=False)
# Order is not preserved
Expand Down Expand Up @@ -2560,7 +2560,8 @@ def test_mark_channel_roundtrip(tmp_path):

ch_names = raw.ch_names
# first mark all channels as good
mark_channels(bids_path, ch_names=[], status="good", verbose=False)
with pytest.warns(FutureWarning, match=r"`mark_channels\(\.\.\., ch_names=\[\]\)`"):
mark_channels(bids_path, ch_names=[], status="good", verbose=False)
tsv_data = _from_tsv(channels_fname)
assert all(status == "good" for status in tsv_data["status"])

Expand Down
29 changes: 23 additions & 6 deletions mne_bids/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -2522,8 +2522,14 @@ def mark_channels(bids_path, *, ch_names, status, descriptions=None, verbose=Non
type (e.g., only EEG or MEG data) is present in the dataset, it will be
selected automatically.
ch_names : str | list of str
The names of the channel(s) to mark with a ``status`` and optionally a
``description``. Can be an empty list to indicate all channel names.
The name(s) of the channel(s) to mark with a ``status`` (and optionally a
``description``). The special value ``"all"`` will mark all channels.
.. versionchanged:: 0.16
The behavior of passing an empty list will change in version 0.17. In version
0.16 and newer, an empty list would mark *all* channels. In version 0.17 and
later, an empty list will be a no-op (no channels will be marked/changed).
status : 'good' | 'bad' | list of str
The status of the channels ('good', or 'bad'). If it is a list, then must be a
list of 'good', or 'bad' that has the same length as ``ch_names``.
Expand Down Expand Up @@ -2586,10 +2592,21 @@ def mark_channels(bids_path, *, ch_names, status, descriptions=None, verbose=Non

# if an empty list is passed in, then these are the entire list
# of channels
if ch_names == []:
ch_names = tsv_data["name"]
elif isinstance(ch_names, str):
ch_names = [ch_names]
if list(ch_names) == []: # casting to list avoids error if ch_names is np.ndarray
warn(
"In version 0.17, the behavior of `mark_channels(..., ch_names=[])` will "
"change, from marking *all* channels to marking *no* channels. Pass "
"ch_names='all' instead of ch_names=[] to keep the old behavior and "
"avoid this warning.",
FutureWarning,
)
ch_names = "all"
# TODO ↑↑↑ remove prior conditional block after 0.16 release ↑↑↑
if isinstance(ch_names, str):
if ch_names == "all":
ch_names = tsv_data["name"]
else:
ch_names = [ch_names]

# set descriptions based on how it's passed in
if isinstance(descriptions, str):
Expand Down

0 comments on commit cb32a98

Please sign in to comment.