Skip to content

Commit

Permalink
FIX: Closer
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Oct 1, 2023
1 parent a5abcca commit 8ea8727
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mne/_fiff/meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3360,7 +3360,7 @@ def _force_update_info(info_base, info_target):
The Info object(s) you wish to overwrite using info_base. These objects
will be modified in-place.
"""
exclude_keys = ["chs", "ch_names", "nchan"]
exclude_keys = ["chs", "ch_names", "nchan", "bads"]
info_target = np.atleast_1d(info_target).ravel()
all_infos = np.hstack([info_base, info_target])
for ii in all_infos:
Expand Down
10 changes: 8 additions & 2 deletions mne/_fiff/tests/test_meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
_dt_to_stamp,
_add_timedelta_to_stamp,
_read_extended_ch_info,
MNEBadsList,
)
from mne.minimum_norm import (
make_inverse_operator,
Expand Down Expand Up @@ -487,8 +488,8 @@ def test_check_consistency():

# Bad channels that are not in the info object
info2 = info.copy()
info2["bads"] = ["b", "foo", "bar"]
pytest.raises(RuntimeError, info2._check_consistency)
with pytest.raises(ValueError, match="do not exist"):
info2["bads"] = ["b", "foo", "bar"]

# Bad data types
info2 = info.copy()
Expand Down Expand Up @@ -1093,14 +1094,19 @@ def test_info_bad():
info[key] = info[key]
with pytest.raises(ValueError, match="between meg<->head"):
info["dev_head_t"] = Transform("mri", "head", np.eye(4))
assert isinstance(info["bads"], MNEBadsList)
with pytest.raises(ValueError, match="do not exist in info"):
info["bads"] = ["foo"]
assert isinstance(info["bads"], MNEBadsList)
with pytest.raises(ValueError, match="do not exist in info"):
info["bads"] += ["foo"]
assert isinstance(info["bads"], MNEBadsList)
with pytest.raises(ValueError, match="do not exist in info"):
info["bads"].append("foo")
assert isinstance(info["bads"], MNEBadsList)
with pytest.raises(ValueError, match="do not exist in info"):
info["bads"].extend(["foo"])
assert isinstance(info["bads"], MNEBadsList)
assert info["bads"] == info["ch_names"][:1] # unchonged


Expand Down
6 changes: 2 additions & 4 deletions mne/forward/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,9 @@ def _read_forward_meas_info(tree, fid):
else:
raise ValueError("MEG/head coordinate transformation not found")

info["bads"] = _read_bad_channels(
fid, parent_meg, ch_names_mapping=ch_names_mapping
)
bads = _read_bad_channels(fid, parent_meg, ch_names_mapping=ch_names_mapping)
# clean up our bad list, old versions could have non-existent bads
info["bads"] = [bad for bad in info["bads"] if bad in info["ch_names"]]
info["bads"] = [bad for bad in bads if bad in info["ch_names"]]

# Check if a custom reference has been applied
tag = find_tag(fid, parent_mri, FIFF.FIFF_MNE_CUSTOM_REF)
Expand Down

0 comments on commit 8ea8727

Please sign in to comment.