Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Split function and new_unit_ids definition #2694 #2695

wants to merge 2 commits into from

Conversation

OlivierPeron
Copy link
Contributor

Change discussed in issue #2694

@alejoe91 alejoe91 added the curation Related to curation module label Apr 10, 2024
@@ -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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

@OlivierPeron OlivierPeron Apr 11, 2024

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.

Copy link
Member

@alejoe91 alejoe91 Apr 11, 2024

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.

Copy link
Collaborator

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.

@alejoe91
Copy link
Member

Closing in favor of #2775

@alejoe91 alejoe91 closed this Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
curation Related to curation module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split function and new_unit_ids definition
3 participants