Skip to content

Commit

Permalink
Adding docs and fixing some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javiber committed May 8, 2024
1 parent f348888 commit a2b4455
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: temporian.EventSet.moving_quantile
53 changes: 52 additions & 1 deletion temporian/core/event_set_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3224,7 +3224,58 @@ def moving_quantile(
quantile: float,
sampling: Optional[EventSetOrNode] = None,
) -> EventSetOrNode:
""" """
"""Computes the quantile in a sliding window over an
[`EventSet`][temporian.EventSet].
For each t in sampling, and for each feature independently, returns at
time t the appropiated quantile for the feature in the window
(t - window_length, t].
`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.
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
values.
The quantile calculated in each window is equivalent to numpy's
`"averaged_inverted_cdf"` method.
Example:
```python
>>> a = tp.event_set(
... timestamps=[0, 1, 2, 5, 6, 7],
... features={"value": [np.nan, 1, 5, 10, 15, 20]},
... )
>>> a.moving_quantile(tp.duration.seconds(4), quantile=0.5)
indexes: ...
(6 events):
timestamps: [0. 1. 2. 5. 6. 7.]
'value': [ nan 1. 3. 7.5 12.5 15. ]
...
```
See [`EventSet.moving_count()`][temporian.EventSet.moving_count] for
examples of moving window operations with external sampling and indices.
Args:
window_length: Sliding window's length.
quantile: the desired quantile defined in the range (0, 1).
sampling: Timestamps to sample the sliding window's value at. If not
provided, timestamps in the input are used.
Returns:
EventSet containing the moving standard deviation of each feature in
the input.
"""
from temporian.core.operators.window.moving_quantile import (
moving_quantile,
)
Expand Down
1 change: 1 addition & 0 deletions temporian/core/test/registered_operators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def test_base(self):
"MOVING_MAX",
"MOVING_MIN",
"MOVING_PRODUCT",
"MOVING_QUANTILE",
"MOVING_STANDARD_DEVIATION",
"MOVING_SUM",
"MULTIPLICATION",
Expand Down

0 comments on commit a2b4455

Please sign in to comment.