Skip to content

Commit

Permalink
add doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
ianspektor committed Sep 12, 2023
1 parent 15a7c0f commit 218a65d
Showing 1 changed file with 58 additions and 31 deletions.
89 changes: 58 additions & 31 deletions temporian/core/event_set_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,11 +1391,12 @@ def moving_count(
Create a tp.int32 feature containing the number of events in the time
window (t - window_length, t].
If `sampling` is provided samples the moving window's value at each
timestamp in `sampling`, else samples it at each timestamp in
`window_length` if it is an `EventSet`, else in the input. If both
`sampling` and `window_length` are provided as `EventSets`, their
sampling must be the same.
`sampling` can't be specified if a variable `window_length` is
specified (i.e. if `window_length` is an EventSet).
If `sampling` is specified or `window_length` is an EventSet, the moving
window is sampled at each timestamp in them, else it is sampled on the
input's.
Example without sampling:
```python
Expand Down Expand Up @@ -1424,6 +1425,27 @@ def moving_count(
```
Example with variable window length:
```python
>>> a = tp.event_set(timestamps=[0, 1, 2, 5])
>>> b = tp.event_set(
... timestamps=[0, 3, 3, 3, 9],
... features={
... "w": [1, 0.5, 3.5, 2.5, 5],
... },
... )
>>> c = a.moving_count(window_length=b)
>>> c
indexes: []
features: [('count', int32)]
events:
(5 events):
timestamps: [0. 3. 3. 3. 9.]
'count': [1 0 3 2 1]
...
```
Example with index:
```python
>>> a = tp.event_set(
Expand Down Expand Up @@ -1475,11 +1497,12 @@ def moving_max(
returns at time t the max of non-nan values for the feature in the window
(t - window_length, t].
If `sampling` is provided samples the moving window's value at each
timestamp in `sampling`, else samples it at each timestamp in
`window_length` if it is an `EventSet`, else in the input. If both
`sampling` and `window_length` are provided as `EventSets`, their
sampling must be the same.
`sampling` can't be specified if a variable `window_length` is
specified (i.e. if `window_length` is an EventSet).
If `sampling` is specified or `window_length` is an EventSet, the moving
window is sampled at each timestamp in them, else it is sampled on the
input's.
If the window does not contain any values (e.g., all the values are
missing, or the window does not contain any sampling), outputs missing
Expand Down Expand Up @@ -1529,11 +1552,12 @@ def moving_min(
returns at time t the minimum of non-nan values for the feature in the window
(t - window_length, t].
If `sampling` is provided samples the moving window's value at each
timestamp in `sampling`, else samples it at each timestamp in
`window_length` if it is an `EventSet`, else in the input. If both
`sampling` and `window_length` are provided as `EventSets`, their
sampling must be the same.
`sampling` can't be specified if a variable `window_length` is
specified (i.e. if `window_length` is an EventSet).
If `sampling` is specified or `window_length` is an EventSet, the moving
window is sampled at each timestamp in them, else it is sampled on the
input's.
If the window does not contain any values (e.g., all the values are
missing, or the window does not contain any sampling), outputs missing
Expand Down Expand Up @@ -1583,11 +1607,12 @@ def moving_standard_deviation(
time t the standard deviation for the feature in the window
(t - window_length, t].
If `sampling` is provided samples the moving window's value at each
timestamp in `sampling`, else samples it at each timestamp in
`window_length` if it is an `EventSet`, else in the input. If both
`sampling` and `window_length` are provided as `EventSets`, their
sampling must be the same.
`sampling` can't be specified if a variable `window_length` is
specified (i.e. if `window_length` is an EventSet).
If `sampling` is specified or `window_length` is an EventSet, the moving
window is sampled at each timestamp in them, else it is sampled on the
input's.
Missing values (such as NaNs) are ignored.
Expand Down Expand Up @@ -1641,13 +1666,14 @@ def moving_sum(
[`EventSet`][temporian.EventSet].
For each t in sampling, and for each feature independently, returns at
time t the sum of the feature in the window (t - window_length, t].
time t the sum of the feature in the window (
If `sampling` is provided samples the moving window's value at each
timestamp in `sampling`, else samples it at each timestamp in
`window_length` if it is an `EventSet`, else in the input. If both
`sampling` and `window_length` are provided as `EventSets`, their
sampling must be the same.
in them. `sampling` can't be specified if `window_length` is an EventSet.ta variable - window_length
specified, (i.e. if `window_length` is an EventSet).
If `sampling` is specified or `window_length` is an EventSet, the moving
window is sampled at each timesta, else it is sampled on the
input's.p
Missing values (such as NaNs) are ignored.
Expand Down Expand Up @@ -2196,11 +2222,12 @@ def simple_moving_average(
time t the average value of the feature in the window
(t - window_length, t].
If `sampling` is provided samples the moving window's value at each
timestamp in `sampling`, else samples it at each timestamp in
`window_length` if it is an `EventSet`, else in the input. If both
`sampling` and `window_length` are provided as `EventSets`, their
sampling must be the same.
`sampling` can't be specified if a variable `window_length` is
specified (i.e. if `window_length` is an EventSet).
If `sampling` is specified or `window_length` is an EventSet, the moving
window is sampled at each timestamp in them, else it is sampled on the
input's.
Missing values (such as NaNs) are ignored.
Expand Down

0 comments on commit 218a65d

Please sign in to comment.