Skip to content

Commit

Permalink
Merge pull request #3052 from h-mayorquin/improve_error
Browse files Browse the repository at this point in the history
Add more helpful error when a non-existent id is passed to extractors
  • Loading branch information
alejoe91 authored Jul 5, 2024
2 parents 5b458ee + c95c435 commit f800954
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/spikeinterface/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f800954

Please sign in to comment.