PolarsTS

Time series handling on top of polars: a TSPolars object that keeps track of
the time index and the panel keys, with methods for sorting, lagging,
differencing and validation.

This is an independent project, not affiliated with the polars development team.


INSTALLATION

    pip install PolarsTS


THE TSPOLARS OBJECT

TSPolars wraps a polars DataFrame and remembers three things: which column is
the time index (ts_col), which columns identify each series in a panel
(id_cols), and what kind of time step the index represents (ts_op).

    import polars as pl
    import PolarsTS as cln

    ts = cln.TSPolars(df, ts_col='fecha', id_cols=['region'], ts_op='yearmonth')

Valid values for ts_op: yearweek, yearmonth, yearquarter, date, datetime,
time, int.

Any polars method works directly on the object and returns a new TSPolars, so
the index and the keys survive the operation.


LAGS

add_lags creates lagged columns named L1x, L2x, and so on, computed within each
key so values never leak across series.

    ts.add_lags(n_lags = 3)
    ts.add_lags(var = 'ipc', n_lags = 6)
    ts.add_lags(lags = {'ipc': 3, 'ventas': [1, 6, 12]})

rem_lags is the inverse and takes the same arguments.


OTHER METHODS

    valid(keys_policy, n_keys_allowed)  checks the object before using it
    sort_ts(keys_first)                 sorts by keys and index
    group_lags(response)                puts each variable next to its lags
    dif_vars(var)                       differences the given variables
    format_ts_col()                     formats the index as text per ts_op

Every method takes inplace: with False (the default) it returns a new object,
with True it modifies the existing one.


LICENSE

MIT. See the LICENSE file.