diff --git a/mne/_fiff/meas_info.py b/mne/_fiff/meas_info.py index bd26501092d..98f8736ad23 100644 --- a/mne/_fiff/meas_info.py +++ b/mne/_fiff/meas_info.py @@ -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: diff --git a/mne/_fiff/tests/test_meas_info.py b/mne/_fiff/tests/test_meas_info.py index abfa2ec291a..cdbeb1d8e44 100644 --- a/mne/_fiff/tests/test_meas_info.py +++ b/mne/_fiff/tests/test_meas_info.py @@ -59,6 +59,7 @@ _dt_to_stamp, _add_timedelta_to_stamp, _read_extended_ch_info, + MNEBadsList, ) from mne.minimum_norm import ( make_inverse_operator, @@ -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() @@ -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 diff --git a/mne/forward/forward.py b/mne/forward/forward.py index 0fcb821ab2d..59c3b5f4691 100644 --- a/mne/forward/forward.py +++ b/mne/forward/forward.py @@ -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)