diff --git a/pynapple/core/interval_set.py b/pynapple/core/interval_set.py index 96663323..44103d80 100644 --- a/pynapple/core/interval_set.py +++ b/pynapple/core/interval_set.py @@ -112,10 +112,10 @@ class IntervalSet(NDArrayOperatorsMixin, _MetadataMixin): >>> end = [5, 12, 33] >>> metadata = {"label": ["a", "b", "c"]} >>> ep = nap.IntervalSet(start=start, end=end, metadata=metadata) - index start end label - 0 0 5 | a - 1 10 12 | b - 2 20 33 | c + index start end label + 0 0 5 a + 1 10 12 b + 2 20 33 c shape: (3, 2), time unit: sec. Initialize an IntervalSet with a pandas DataFrame: @@ -124,10 +124,10 @@ class IntervalSet(NDArrayOperatorsMixin, _MetadataMixin): >>> df = pd.DataFrame(data={"start": [0, 10, 20], "end": [5, 12, 33], "label": ["a", "b", "c"]}) >>> ep = nap.IntervalSet(df) >>> ep - index start end label - 0 0 5 | a - 1 10 12 | b - 2 20 33 | c + index start end label + 0 0 5 a + 1 10 12 b + 2 20 33 c shape: (3, 2), time unit: sec. Apply numpy functions to an IntervalSet: @@ -1054,10 +1054,10 @@ def set_info(self, metadata=None, **kwargs): >>> metadata = pd.DataFrame(data=['left','right','left'], columns=['choice']) >>> ep.set_info(metadata) >>> ep - index start end choice - 0 0 5 | left - 1 10 12 | right - 2 20 33 | left + index start end choice + 0 0 5 left + 1 10 12 right + 2 20 33 left shape: (3, 2), time unit: sec. To add metadata with a dictionary: @@ -1065,10 +1065,10 @@ def set_info(self, metadata=None, **kwargs): >>> metadata = {"reward": [1, 0, 1]} >>> ep.set_info(metadata) >>> ep - index start end choice reward - 0 0 5 | left 1 - 1 10 12 | right 0 - 2 20 33 | left 1 + index start end choice reward + 0 0 5 left 1 + 1 10 12 right 0 + 2 20 33 left 1 shape: (3, 2), time unit: sec. To add metadata with a keyword argument (pd.Series, numpy.ndarray, list or tuple): @@ -1076,40 +1076,40 @@ def set_info(self, metadata=None, **kwargs): >>> stim = pd.Series(data = [10, -23, 12]) >>> ep.set_info(stim=stim) >>> ep - index start end choice reward stim - 0 0 5 | left 1 10 - 1 10 12 | right 0 -23 - 2 20 33 | left 1 12 + index start end choice reward stim + 0 0 5 left 1 10 + 1 10 12 right 0 -23 + 2 20 33 left 1 12 shape: (3, 2), time unit: sec. To add metadata as an attribute: >>> ep.label = ["a", "b", "c"] >>> ep - index start end choice reward label - 0 0 5 | left 1 a - 1 10 12 | right 0 b - 2 20 33 | left 1 c + index start end choice reward label + 0 0 5 left 1 a + 1 10 12 right 0 b + 2 20 33 left 1 c shape: (3, 2), time unit: sec. To add metadata as a key: >>> ep["error"] = [0, 0, 0] >>> ep - index start end choice reward label error - 0 0 5 | left 1 a 0 - 1 10 12 | right 0 b 0 - 2 20 33 | left 1 c 0 + index start end choice reward label error + 0 0 5 left 1 a 0 + 1 10 12 right 0 b 0 + 2 20 33 left 1 c 0 shape: (3, 2), time unit: sec. Metadata can be overwritten: >>> ep.set_info(label=["x", "y", "z"]) >>> ep - index start end choice reward label error - 0 0 5 | left 1 x 0 - 1 10 12 | right 0 y 0 - 2 20 33 | left 1 z 0 + index start end choice reward label error + 0 0 5 left 1 x 0 + 1 10 12 right 0 y 0 + 2 20 33 left 1 z 0 shape: (3, 2), time unit: sec. """ _MetadataMixin.set_info(self, metadata, **kwargs) diff --git a/tests/test_ts_group.py b/tests/test_ts_group.py index bd5b3cc4..04cab0ff 100644 --- a/tests/test_ts_group.py +++ b/tests/test_ts_group.py @@ -424,6 +424,10 @@ def test_repr_(self, group): ) assert tabulate(lines, headers=headers) == tsgroup.__repr__() + # Empty TsGroup + empty_tsg = nap.TsGroup({}, time_support=nap.IntervalSet(0, 10)) + assert tabulate([], headers=["Index", "rate"]) == empty_tsg.__repr__() + def test_str_(self, group): tsgroup = nap.TsGroup(group) assert tsgroup.__str__() == tsgroup.__repr__()