mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.7k stars 1.31k forks source link

Dropping all channels raises "No channels match the selection" #12762

Closed Farzin-Negahbani closed 2 months ago

Farzin-Negahbani commented 2 months ago

Description of the problem

Dropping all channels raises a 'ValueError: No channels match the selection,' which might be a bit confusing. Adding a more specific error message could help.

Steps to reproduce

import mne
from mne.datasets import sample

data_path = sample.data_path()
meg_path = data_path / "MEG" / "sample"
raw = mne.io.read_raw_fif(meg_path / "sample_audvis_raw.fif")

# Dropping all channels
raw.drop_channels(raw.info["ch_names"])

Link to data

No response

Expected results

Maybe a more clear message can be:

RuntimeError: Cannot drop all channels

Actual results

Traceback (most recent call last):
  File "~/lib/python3.12/site-packages/mne/channels/channels.py", line 604, in drop_channels
    return self._pick_drop_channels(idx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<decorator-gen-133>", line 12, in _pick_drop_channels
  File "~/lib/python3.12/site-packages/mne/channels/channels.py", line 627, in _pick_drop_channels
    pick_info(self.info, idx, copy=False)
  File "<decorator-gen-8>", line 12, in pick_info
  File "~/lib/python3.12/site-packages/mne/_fiff/pick.py", line 627, in pick_info
    raise ValueError("No channels match the selection.")
ValueError: No channels match the selection.

Additional information

Platform Linux-5.15.0-116-generic-x86_64-with-glibc2.35 Python 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:23:07) [GCC 12.3.0] Executable ~/bin/python3.12 CPU x86_64 (16 cores) Memory 62.7 GB

Core ├☑ mne 1.7.1 (latest release) ├☑ numpy 1.26.4 (OpenBLAS 0.3.27 with 16 threads) ├☑ scipy 1.14.0 └☑ matplotlib 3.9.1 (backend=qtagg)

Numerical (optional) ├☑ sklearn 1.5.1 ├☑ numba 0.60.0 ├☑ nibabel 5.2.1 ├☑ nilearn 0.10.4 ├☑ dipy 1.9.0 ├☑ openmeeg 2.5.12 ├☑ pandas 2.2.2 ├☑ h5io 0.2.4 ├☑ h5py 3.11.0 └☐ unavailable cupy

Visualization (optional) ├☑ pyvista 0.44.1 (OpenGL 4.5 (Core Profile) Mesa 24.1.4 via llvmpipe (LLVM 18.1.8, 256 bits)) ├☑ pyvistaqt 0.11.1 ├☑ vtk 9.3.1 ├☑ qtpy 2.4.1 (PySide6=6.7.2) ├☑ ipympl 0.9.4 ├☑ pyqtgraph 0.13.7 ├☑ mne-qt-browser 0.6.3 ├☑ ipywidgets 8.1.3 ├☑ trame_client 3.2.1 ├☑ trame_server 3.0.3 ├☑ trame_vtk 2.8.9 └☑ trame_vuetify 2.6.2

Ecosystem (optional) ├☑ mne-connectivity 0.7.0 ├☑ mne-icalabel 0.6.0 ├☑ eeglabio 0.0.2-4 ├☑ edfio 0.4.3 ├☑ mffpy 0.9.0 ├☑ pybv 0.7.5 └☐ unavailable mne-bids, mne-nirs, mne-features, mne-bids-pipeline, neo

welcome[bot] commented 2 months ago

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

larsoner commented 2 months ago

Agreed, we shouldn't allow someone to drop all channels, a ValueError that all channels would be dropped would seem more appropriate. Would you be up for trying a PR to add this @Farzin-Negahbani ?

Farzin-Negahbani commented 2 months ago

Sure!