Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gviejo committed Dec 11, 2024
1 parent 69931b5 commit d624035
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 32 deletions.
64 changes: 32 additions & 32 deletions pynapple/core/interval_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -1054,62 +1054,62 @@ 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:
>>> 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):
>>> 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)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_ts_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down

0 comments on commit d624035

Please sign in to comment.