From 3784c3898ee521b057bc3962fb66e2eecc561cfe Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Wed, 19 Jun 2024 15:08:26 -0600 Subject: [PATCH 1/3] use the value instead of book --- src/spikeinterface/core/base.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/core/base.py b/src/spikeinterface/core/base.py index 6fbc5ac289..05f59e5349 100644 --- a/src/spikeinterface/core/base.py +++ b/src/spikeinterface/core/base.py @@ -56,7 +56,7 @@ def __init__(self, main_ids: Sequence) -> None: # "main_ids" will either be channel_ids or units_ids # They are used for properties - self._main_ids = np.array(main_ids) + self._main_ids = np.asarray(main_ids) if len(self._main_ids) > 0: assert ( self._main_ids.dtype.kind in "uiSU" @@ -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) + indices = np.array([_main_ids.index(id) for id in ids], dtype=np.int) + if prefer_slice: if np.all(np.diff(indices) == 1): indices = slice(indices[0], indices[-1] + 1) From e2b1a3b734245e696b8e83d73354a62161f8fcff Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Wed, 19 Jun 2024 15:22:41 -0600 Subject: [PATCH 2/3] int went flying --- src/spikeinterface/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/base.py b/src/spikeinterface/core/base.py index 05f59e5349..a7b250690f 100644 --- a/src/spikeinterface/core/base.py +++ b/src/spikeinterface/core/base.py @@ -138,7 +138,7 @@ def ids_to_indices( raise ValueError(error_msg) _main_ids = self._main_ids.tolist() - indices = np.array([_main_ids.index(id) for id in ids], dtype=np.int) + indices = np.array([_main_ids.index(id) for id in ids], dtype=int) if prefer_slice: if np.all(np.diff(indices) == 1): From c95c4357126eab2619cdffe5826409689638df0c Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Tue, 2 Jul 2024 07:12:51 -0600 Subject: [PATCH 3/3] Update src/spikeinterface/core/base.py --- src/spikeinterface/core/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/base.py b/src/spikeinterface/core/base.py index a7b250690f..dcb80d2a67 100644 --- a/src/spikeinterface/core/base.py +++ b/src/spikeinterface/core/base.py @@ -56,7 +56,7 @@ def __init__(self, main_ids: Sequence) -> None: # "main_ids" will either be channel_ids or units_ids # They are used for properties - self._main_ids = np.asarray(main_ids) + self._main_ids = np.array(main_ids) if len(self._main_ids) > 0: assert ( self._main_ids.dtype.kind in "uiSU"