Skip to content

Commit

Permalink
make IntervalSet(start_end_pairs) initialization clearer and more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
eschombu committed Aug 9, 2024
1 parent 0896026 commit fc6f731
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pynapple/core/interval_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ def __init__(self, start, end=None, time_units="s"):
Parameters
----------
start : numpy.ndarray or number or pandas.DataFrame or pandas.Series or iterable of (start, end) pairs
Beginning of intervals
Beginning of intervals. Alternatively, the `end` argument can be left out and `start` can be one of the
following:
- IntervalSet
- pandas.DataFrame with columns ["start", "end"]
- iterable of (start, end) pairs
- a single (start, end) pair
end : numpy.ndarray or number or pandas.Series, optional
Ends of intervals
time_units : str, optional
Expand Down Expand Up @@ -128,13 +133,12 @@ def __init__(self, start, end=None, time_units="s"):
if end is None:
# Require iterable of (start, end) tuples
try:
start_end_array = np.array(list(start))
if start_end_array.ndim == 1:
start, end = start_end_array
else:
start, end = zip(*start_end_array)
start_end_array = np.array(list(start)).reshape(-1, 2)
start, end = zip(*start_end_array)
except (TypeError, ValueError):
raise ValueError("Unable to Interpret the input. Please provide a list of start-end intervals.")
raise ValueError(
"Unable to Interpret the input. Please provide a list of start-end pairs."
)

args = {"start": start, "end": end}

Expand Down

0 comments on commit fc6f731

Please sign in to comment.