resolve_lag_sequence

resolve_lag_sequence(lags, index, clamp=True)

Normalise lag specifications into a sorted numpy array of non-negative integers.

Parameters

Name Type Description Default
lags (str, int, Sequence[int], range, slice) - String durations (e.g. "30 days", "3 months") are converted to the number of observation lags implied by index. - Integers produce a range(0, lags) style sequence (inclusive). - Sequences/ranges/slices are materialised and sorted. required
index array - like A date/time index used to translate duration strings into row counts. The index is sorted internally. required
clamp bool If True (default), lags greater than len(index) - 1 are clipped. True

Returns

Name Type Description
np.ndarray Sorted array of lag integers starting at zero.

Raises

Name Type Description
ValueError When the input cannot be interpreted or the index is empty.

Examples

import numpy as np
import pandas as pd
import pytimetk as tk

idx = pd.date_range("2020-01-01", periods=5, freq="D")
tk.resolve_lag_sequence("3 days", idx)
array([0, 1, 2, 3])
tk.resolve_lag_sequence([0, 2, 4], idx)
array([0, 2, 4])