Skip to content

Commit

Permalink
get_info examples for tsdframe
Browse files Browse the repository at this point in the history
  • Loading branch information
sjvenditto committed Nov 21, 2024
1 parent b11227e commit 7bd540a
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions pynapple/core/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,78 @@ def set_info(self, metadata=None, **kwargs):
"""
_MetadataMixin.set_info(self, metadata, **kwargs)

@add_meta_docstring("get_info")
def get_info(self, key):
"""
Examples
--------
>>> import pynapple as nap
>>> import numpy as np
>>> metadata = {"l1": [1, 2, 3], "l2": ["x", "x", "y"]}
>>> tsdframe = nap.TsdFrame(t=np.arange(5), d=np.ones((5, 3)), metadata=metadata)
To access a single metadata column:
>>> tsdframe.get_info("l1")
0 1
1 2
2 3
Name: l1, dtype: int64
To access multiple metadata columns:
>>> tsdframe.get_info(["l1", "l2"])
l1 l2
0 1 x
1 2 x
2 3 y
To access metadata of a single index:
>>> tsdframe.get_info(0)
rate 0.667223
l1 1
l2 x
Name: 0, dtype: object
To access metadata of multiple indices:
>>> tsdframe.get_info([0, 1])
rate l1 l2
0 0.667223 1 x
1 1.334445 2 x
To access metadata of a single index and column:
>>> tsdframe.get_info((0, "l1"))
np.int64(1)
To access metadata as an attribute:
>>> tsdframe.l1
0 1
1 2
2 3
Name: l1, dtype: int64
To access metadata as a key:
>>> tsdframe["l1"]
0 1
1 2
2 3
Name: l1, dtype: int64
Multiple metadata columns can be accessed as keys:
>>> tsdframe[["l1", "l2"]]
l1 l2
0 1 x
1 2 x
2 3 y
"""
_MetadataMixin.get_info(self, key)


class Tsd(_BaseTsd):
"""
Expand Down

0 comments on commit 7bd540a

Please sign in to comment.