-
Notifications
You must be signed in to change notification settings - Fork 64
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
IntervalSet creation from (start, end) pairs #304
Conversation
pynapple/core/interval_set.py
Outdated
@@ -94,7 +94,7 @@ def __init__(self, start, end=None, time_units="s", **kwargs): | |||
|
|||
Parameters | |||
---------- | |||
start : numpy.ndarray or number or pandas.DataFrame or pandas.Series | |||
start : numpy.ndarray or number or pandas.DataFrame or pandas.Series or iterable of (start, end) pairs | |||
Beginning of intervals |
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.
I would add more description here.
I agree for the flexibility and I think the new argument for IntervalSet makes sense. For TsGroup, I would not do it as I can see it being hard to maintain on the long run. In this case, forcing to pass an IntervalSet is probably easier. |
pynapple/core/interval_set.py
Outdated
try: | ||
start_end_array = np.array(list(start)) | ||
if start_end_array.ndim == 1: | ||
start, end = start_end_array |
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.
I am not sure I understand this. In this case you need to have start_end_array being of size 2 but you check for ndim?
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.
I was allowing the case of ValueError
raised by the ndim == 1
case with size != 2
to be handled by the try...except
block, but I think you're right that this wasn't the clearest and best way to handle this. Hopefully the modified version is clearer.
tests/test_ts_group.py
Outdated
@@ -90,6 +90,15 @@ def test_create_ts_group_with_time_support(self, group): | |||
assert np.all(first >= ep[0, 0]) | |||
assert np.all(last <= ep[0, 1]) | |||
|
|||
def test_create_ts_group_with_time_support_tuple(self, group): |
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.
I would remove this one
pynapple/core/ts_group.py
Outdated
@@ -124,6 +124,14 @@ def __init__( | |||
|
|||
self._metadata = pd.DataFrame(index=self.index, columns=["rate"], dtype="float") | |||
|
|||
# If time_support is passed, all elements of data are restricted prior to init |
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.
I would force IntervalSet here.
041b7af
to
783499e
Compare
783499e
to
fc6f731
Compare
Ok, I took out the portion where non- |
Thank you Eric |
It's a bit counter-intuitive sometimes to split up a sequence of intervals into the starts and ends, and easier sometimes to write a sequence of start-end pairs. This change allows the
IntervalSet
to accept such a sequence of pairs, or a single pair.Example:
I also added the capability to pass a variable that can be used forIntervalSet
creation to thetime_support
parameter duringTsGroup
initialization. Meaning, iftime_support
is not anIntervalSet
instance,time_support = IntervalSet(time_support)
will be attempted.I added tests and updated the doc string. This is my first PR to the repo, so more than happy for feedback on: