-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split function and new_unit_ids definition #2694 #2695
Conversation
Change discussed in issue #2694
@@ -61,7 +61,9 @@ def _get_unused_id(self, n=1): | |||
|
|||
def split(self, split_unit_id, indices_list): | |||
current_sorting = self._sorting_stages[self._sorting_stages_i] | |||
new_unit_ids = self._get_unused_id(2) | |||
if type(indices_list) is not list: | |||
indices_list = [indices_list] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indices_list = [indices_list] | |
indices_list = list(indices_list) |
Is this the right solution? for example if I do:
indices_list = np.array([1,2,3])
this will turn this into indices_list = [array([1,2,3])] instead of indices_list = [1,2,3]
whereas using the list constructor will work correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What we want is something like indices_list = [array([1,2,3])]
, with one array per recording' segment. If you have indices_list = [1,2,3]
then this max([v.max() for v in indices_list]) + 1
could raise an AttributeError: 'int' object has no attribute 'max'
if v is int instead of np.int, but anyway the point is that v should be an array and not a value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just doing np.max(v)
instead ov v.max()
? the former works both for lists and array.
Regarding the checks, we should also check that indices_list[0]
is an iterable, so I would do this:
from collections.abc import Iterable
...
if not isinstance(indices_list, list):
indices_list = [indices_list]
if not isinstance(indices_list[0], Iterable):
raise ValueError(...)
new_unit_ids = self._get_unused_id(np.max([np.max(v) for v in indices_list]) + 1)
This protects from passing indices_list=[1,2,3]
, which should fail in my opinion. Instead, passing np.array([1,2,3])
or [[1,2,3]]
should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This protects from passing indices_list=[1,2,3], which should fail in my opinion. Instead, passing np.array([1,2,3]) or [[1,2,3]] should work.
Exactly. Because we were just checking list I was confused. I also think we need a docstring in this case. Needing a list of a list or an array is not intuitive for a variable named indices_list. With a docstring at least the user can be warned what is expected.
Co-authored-by: Alessio Buccino <[email protected]>
Closing in favor of #2775 |
Change discussed in issue #2694