diff --git a/doc/changes/devel/12763.bugfix.rst b/doc/changes/devel/12763.bugfix.rst new file mode 100644 index 00000000000..405abd19313 --- /dev/null +++ b/doc/changes/devel/12763.bugfix.rst @@ -0,0 +1 @@ +Fix check for dropping all channels in :meth:`mne.io.Raw.drop_channels` and related methods, by :newcontrib:`Farzin Negahbani`. \ No newline at end of file diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 34195e4ce47..97a562bc7fb 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -168,6 +168,8 @@ .. _Fahimeh Mamashli: https://github.com/fmamashli +.. _Farzin Negahbani: https://github.com/Farzin-Negahbani + .. _Federico Raimondo: https://github.com/fraimondo .. _Federico Zamberlan: https://github.com/fzamberlan @@ -508,6 +510,8 @@ .. _Rotem Falach: https://github.com/Falach +.. _Sammi Chekroud: https://github.com/schekroud + .. _Samu Taulu: https://phys.washington.edu/people/samu-taulu .. _Samuel Deslauriers-Gauthier: https://github.com/sdeslauriers @@ -536,6 +540,8 @@ .. _Senwen Deng: https://snwn.de +.. _Seyed Yahya Shirazi: https://neuromechanist.github.io + .. _Sheraz Khan: https://github.com/SherazKhan .. _Silvia Cotroneo: https://github.com/sfc-neuro @@ -625,7 +631,3 @@ .. _Zhi Zhang: https://github.com/tczhangzhi/ .. _Zvi Baratz: https://github.com/ZviBaratz - -.. _Seyed Yahya Shirazi: https://neuromechanist.github.io - -.. _Sammi Chekroud: https://github.com/schekroud diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 49890a56e91..92ddb7a9779 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -602,6 +602,8 @@ def drop_channels(self, ch_names, on_missing="raise"): bad_idx = [self.ch_names.index(ch) for ch in ch_names if ch in self.ch_names] idx = np.setdiff1d(np.arange(len(self.ch_names)), bad_idx) + if len(idx) == 0: + raise ValueError("All channels would be dropped.") return self._pick_drop_channels(idx) @verbose diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index 13ed8f23f08..61fe7277156 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -539,6 +539,8 @@ def test_drop_channels(): raw.drop_channels(m_chs, on_missing="warn") # ...or ignored altogether raw.drop_channels(m_chs, on_missing="ignore") + with pytest.raises(ValueError, match="All channels"): + raw.drop_channels(raw.ch_names) def test_pick_channels():