diff --git a/src/spikeinterface/core/base.py b/src/spikeinterface/core/base.py index 6fbc5ac289..dcb80d2a67 100644 --- a/src/spikeinterface/core/base.py +++ b/src/spikeinterface/core/base.py @@ -128,8 +128,18 @@ def ids_to_indices( indices = np.arange(len(self._main_ids)) else: assert isinstance(ids, (list, np.ndarray, tuple)), "'ids' must be a list, np.ndarray or tuple" + + non_existent_ids = [id for id in ids if id not in self._main_ids] + if non_existent_ids: + error_msg = ( + f"IDs {non_existent_ids} are not channel ids of the extractor. \n" + f"Available ids are {self._main_ids} with dtype {self._main_ids.dtype}" + ) + raise ValueError(error_msg) + _main_ids = self._main_ids.tolist() indices = np.array([_main_ids.index(id) for id in ids], dtype=int) + if prefer_slice: if np.all(np.diff(indices) == 1): indices = slice(indices[0], indices[-1] + 1)