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

MAINT: Complete API change of ordered #12534

Merged
merged 3 commits into from
Apr 9, 2024
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
41 changes: 9 additions & 32 deletions mne/_fiff/pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
fill_doc,
logger,
verbose,
warn,
)
from .constants import FIFF

Expand Down Expand Up @@ -258,7 +257,7 @@ def channel_type(info, idx):


@verbose
def pick_channels(ch_names, include, exclude=(), ordered=None, *, verbose=None):
def pick_channels(ch_names, include, exclude=(), ordered=True, *, verbose=None):
"""Pick channels by names.

Returns the indices of ``ch_names`` in ``include`` but not in ``exclude``.
Expand Down Expand Up @@ -290,7 +289,7 @@ def pick_channels(ch_names, include, exclude=(), ordered=None, *, verbose=None):
"""
if len(np.unique(ch_names)) != len(ch_names):
raise RuntimeError("ch_names is not a unique list, picking is unsafe")
_validate_type(ordered, (bool, None), "ordered")
_validate_type(ordered, bool, "ordered")
_check_excludes_includes(include)
_check_excludes_includes(exclude)
if not isinstance(include, list):
Expand All @@ -306,34 +305,12 @@ def pick_channels(ch_names, include, exclude=(), ordered=None, *, verbose=None):
sel.append(ch_names.index(name))
else:
missing.append(name)
dep_msg = (
"The default for pick_channels will change from ordered=False to "
"ordered=True in 1.5"
)
if len(missing):
if ordered is None:
warn(
f"{dep_msg} and this will result in an error because the "
f"following channel names are missing:\n{missing}\n"
"Either fix your included names or explicitly pass "
"ordered=False.",
FutureWarning,
)
elif ordered:
raise ValueError(
f"Missing channels from ch_names required by include:\n{missing}"
)
if len(missing) and ordered:
raise ValueError(
f"Missing channels from ch_names required by include:\n{missing}"
)
if not ordered:
out_sel = np.unique(sel)
if ordered is None and not np.array_equal(out_sel, sel):
warn(
f"{dep_msg} and this will result in a change of behavior "
"because the resulting channel order will not match. Either "
"use a channel order that matches your instance or "
"pass ordered=False.",
FutureWarning,
)
sel = out_sel
sel = np.unique(sel)
return np.array(sel, int)


Expand Down Expand Up @@ -715,7 +692,7 @@ def _has_kit_refs(info, picks):

@verbose
def pick_channels_forward(
orig, include=(), exclude=(), ordered=None, copy=True, *, verbose=None
orig, include=(), exclude=(), ordered=True, copy=True, *, verbose=None
):
"""Pick channels from forward operator.

Expand Down Expand Up @@ -902,7 +879,7 @@ def channel_indices_by_type(info, picks=None):

@verbose
def pick_channels_cov(
orig, include=(), exclude="bads", ordered=None, copy=True, *, verbose=None
orig, include=(), exclude="bads", ordered=True, copy=True, *, verbose=None
):
"""Pick channels from covariance matrix.

Expand Down
3 changes: 1 addition & 2 deletions mne/_fiff/tests/test_pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,7 @@ def test_picks_by_channels():
# duplicate check
names = ["MEG 002", "MEG 002"]
assert len(pick_channels(raw.info["ch_names"], names, ordered=False)) == 1
with pytest.warns(FutureWarning, match="ordered=False"):
assert len(raw.copy().pick_channels(names)[0][0]) == 1 # legacy method OK here
assert len(raw.copy().pick_channels(names, ordered=False)[0][0]) == 1

# missing ch_name
bad_names = names + ["BAD"]
Expand Down
2 changes: 1 addition & 1 deletion mne/channels/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def pick_types(

@verbose
@legacy(alt="inst.pick(...)")
def pick_channels(self, ch_names, ordered=None, *, verbose=None):
def pick_channels(self, ch_names, ordered=True, *, verbose=None):
"""Pick some channels.

Parameters
Expand Down
2 changes: 1 addition & 1 deletion mne/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def plot_topomap(
)

@verbose
def pick_channels(self, ch_names, ordered=None, *, verbose=None):
def pick_channels(self, ch_names, ordered=True, *, verbose=None):
"""Pick channels from this covariance matrix.

Parameters
Expand Down
2 changes: 1 addition & 1 deletion mne/forward/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _merge_fwds(fwds, *, verbose=None):


@verbose
def read_forward_solution(fname, include=(), exclude=(), *, ordered=None, verbose=None):
def read_forward_solution(fname, include=(), exclude=(), *, ordered=True, verbose=None):
"""Read a forward solution a.k.a. lead field.

Parameters
Expand Down
2 changes: 1 addition & 1 deletion mne/time_frequency/csd.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@verbose
def pick_channels_csd(
csd, include=(), exclude=(), ordered=None, copy=True, *, verbose=None
csd, include=(), exclude=(), ordered=True, copy=True, *, verbose=None
):
"""Pick channels from cross-spectral density matrix.

Expand Down
6 changes: 3 additions & 3 deletions mne/utils/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3064,12 +3064,12 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75):

docdict["ordered"] = """
ordered : bool
If True (default False), ensure that the order of the channels in
If True (default), ensure that the order of the channels in
the modified instance matches the order of ``ch_names``.

.. versionadded:: 0.20.0
.. versionchanged:: 1.5
The default changed from False in 1.4 to True in 1.5.
.. versionchanged:: 1.7
The default changed from False in 1.6 to True in 1.7.
"""

docdict["origin_maxwell"] = """
Expand Down
Loading