Skip to content

Commit

Permalink
Added missing examples to tp.save and tp.load
Browse files Browse the repository at this point in the history
  • Loading branch information
javiber committed Apr 17, 2024
1 parent dc8e17f commit c434ab2
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions temporian/core/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ def save(
only EventSetNodes, and save that instead. Note that the partial function
needs to be compiled too, with `tp.compile(partial(...))`.
Example:
```python
>>> a = tp.event_set([0, 1, 2], {"a": [10.0, 20.0, 10.0]})
>>> # define function and compile it
>>> @tp.compile()
... def func(evset):
... return {"avg_evset": evset.simple_moving_average(3)}
>>> # save function
>>> file_path = tmp_dir / "my_prep.tem"
>>> tp.save(func, file_path, evset=a)
>>> # load function
>>> loaded_func = tp.load(file_path)
>>> loaded_func(a)
{'avg_evset': indexes: []
features: [('a', float64)]
events:
(3 events):
timestamps: [0. 1. 2.]
'a': [10. 15. 13.3333]
...
```
Args:
fn: The function to save.
path: The path to save the function to.
Expand Down Expand Up @@ -128,6 +154,32 @@ def load(
The loaded function receives the same positional and keyword arguments and
applies the same operator graph to its inputs as when it was saved.
Example:
```python
>>> a = tp.event_set([0, 1, 2], {"a": [10.0, 20.0, 10.0]})
>>> # define function and compile it
>>> @tp.compile()
... def func(evset):
... return {"avg_evset": evset.simple_moving_average(3)}
>>> # save function
>>> file_path = tmp_dir / "my_prep.tem"
>>> tp.save(func, file_path, evset=a)
>>> # load function
>>> loaded_func = tp.load(file_path)
>>> loaded_func(a)
{'avg_evset': indexes: []
features: [('a', float64)]
events:
(3 events):
timestamps: [0. 1. 2.]
'a': [10. 15. 13.3333]
...
```
Args:
path: The path to load the function from.
Expand Down

0 comments on commit c434ab2

Please sign in to comment.