Skip to content
Open
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
1 change: 1 addition & 0 deletions doc/changes/dev/14006.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a crash (``AttributeError`` on ``NoneType``) when picking channels on a :class:`~mne.io.Raw` whose ``_orig_units`` is ``None``, by `Cedric Conday`_.
7 changes: 4 additions & 3 deletions mne/channels/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,10 @@ def _pick_drop_channels(self, idx, *, verbose=None):

if isinstance(self, BaseRaw):
self.annotations._prune_ch_names(self.info, on_missing="ignore")
self._orig_units = {
k: v for k, v in self._orig_units.items() if k in self.ch_names
}
if self._orig_units:
self._orig_units = {
k: v for k, v in self._orig_units.items() if k in self.ch_names
}

self._pick_projs()
return self
Expand Down
11 changes: 11 additions & 0 deletions mne/channels/tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy.io import savemat

import mne
from mne import (
Epochs,
EpochsArray,
Expand Down Expand Up @@ -696,3 +697,13 @@ def test_combine_channels_metadata():
good = dict(foo=[0, 1, 3, 4], bar=[5, 2]) # good grad and mag
combined_epochs = combine_channels(epochs, good)
pd.testing.assert_frame_equal(epochs.metadata, combined_epochs.metadata)


def test_pick_channels_orig_units_none():
"""Picking channels must not crash when _orig_units is None (gh-11314)."""
info = mne.create_info(["Fp1", "Fp2", "F3", "F4"], 100.0, "eeg")
raw = mne.io.RawArray(np.zeros((4, 100)), info)
raw._orig_units = None # the state reported by some readers / RawArray flows
raw.pick(["Fp1", "Fp2"]) # previously raised AttributeError on None.items()
assert raw.ch_names == ["Fp1", "Fp2"]
assert raw._orig_units is None
Loading