Skip to content

Commit

Permalink
Merge pull request #2324 from DradeAW/ids_tuple
Browse files Browse the repository at this point in the history
ids can be a tuple
  • Loading branch information
alejoe91 authored Dec 13, 2023
2 parents 691fa8d + 17609b3 commit a1b869f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/spikeinterface/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def _check_segment_index(self, segment_index: Optional[int] = None) -> int:
else:
return segment_index

def ids_to_indices(self, ids: list | np.ndarray | None = None, prefer_slice: bool = False) -> np.ndarray | slice:
def ids_to_indices(
self, ids: list | np.ndarray | tuple | None = None, prefer_slice: bool = False
) -> np.ndarray | slice:
"""
Convert a list of IDs into indices, either as an array or a slice.
Expand All @@ -102,7 +104,7 @@ def ids_to_indices(self, ids: list | np.ndarray | None = None, prefer_slice: boo
Parameters
----------
ids : list or np.ndarray
ids : list | np.ndarray | tuple | None, default: None
The array of IDs to be converted into indices. If `None`, it generates indices based on the length of `_main_ids`.
prefer_slice : bool, default: False
If `True`, the function will return a slice object when the indices are consecutive. Default is `False`.
Expand All @@ -120,7 +122,7 @@ def ids_to_indices(self, ids: list | np.ndarray | None = None, prefer_slice: boo
else:
indices = np.arange(len(self._main_ids))
else:
assert isinstance(ids, (list, np.ndarray)), "'ids' must be a list, np.ndarray"
assert isinstance(ids, (list, np.ndarray, tuple)), "'ids' must be a list, np.ndarray or tuple"
_main_ids = self._main_ids.tolist()
indices = np.array([_main_ids.index(id) for id in ids], dtype=int)
if prefer_slice:
Expand Down

0 comments on commit a1b869f

Please sign in to comment.