Polars Time Series Extension
Project description
Polars Time Series Extension
A high-performance time series analysis toolkit for Polars, with Rust-powered distance metrics and Python analytics.
Documentation: https://drumtorben.github.io/polars-ts
Source Code: https://github.com/drumtorben/polars-ts
PyPI: https://pypi.org/project/polars-timeseries
Features
Distance Metrics (Rust, parallelized via Rayon)
| Metric | Function | Key Parameters |
|---|---|---|
| Dynamic Time Warping | compute_pairwise_dtw |
method: standard, sakoe_chiba, itakura, fast |
| Derivative DTW | compute_pairwise_ddtw |
Shape-sensitive comparison |
| Weighted DTW | compute_pairwise_wdtw |
g: weight sharpness |
| Move-Split-Merge | compute_pairwise_msm |
c: move cost |
| Edit Distance (Real Penalty) | compute_pairwise_erp |
g: gap value |
| Longest Common Subsequence | compute_pairwise_lcss |
epsilon: matching threshold |
| Time Warp Edit Distance | compute_pairwise_twe |
nu: stiffness, lambda_: deletion cost |
| Multivariate DTW | compute_pairwise_dtw_multi |
metric: manhattan, euclidean |
| Multivariate MSM | compute_pairwise_msm_multi |
c: move cost |
Trend & Changepoint Detection (Rust)
- Mann-Kendall test — non-parametric trend detection
- Sen's slope — robust trend magnitude estimation
- CUSUM — cumulative sum changepoint detection
Decomposition (Python)
- Seasonal decomposition — additive or multiplicative (classical)
- Fourier decomposition — harmonic decomposition with configurable frequencies
- Decomposition features — trend/seasonal strength extraction (simple or MSTL)
- Anomaly flagging — residual-based anomaly detection from any decomposition
Forecasting
- SCUM — ensemble model combining AutoARIMA, AutoETS, AutoCES, and DynamicOptimizedTheta
- Kaboudan metric — model robustness evaluation via block-shuffle backtesting
Installation
pip install polars-timeseries
Optional dependencies for specific features:
pip install "polars-timeseries[forecast]" # Kaboudan metric, SCUM model
pip install "polars-timeseries[decomposition]" # Fourier decomposition
pip install "polars-timeseries[all]" # Everything
Requires Python 3.12+ and Polars 1.30+.
Quick Start
Pairwise DTW distance
import polars as pl
import polars_ts as pts
df = pl.DataFrame({
"unique_id": ["A"] * 5 + ["B"] * 5,
"y": [1.0, 2.0, 3.0, 2.0, 1.0,
1.0, 3.0, 5.0, 3.0, 1.0],
})
# Standard DTW
result = pts.compute_pairwise_dtw(df, df)
# With Sakoe-Chiba band constraint
result = pts.compute_pairwise_dtw(df, df, method="sakoe_chiba", param=2)
K-Medoids clustering
import polars as pl
import polars_ts as pts
df = pl.DataFrame({
"group": ["A"] * 10 + ["B"] * 10,
"y": list(range(10)) + [10 - x for x in range(10)],
})
"unique_id": ["A"] * 5 + ["B"] * 5 + ["C"] * 5,
"y": [1.0, 1.0, 1.0, 1.0, 1.0, # flat low
5.0, 5.0, 5.0, 5.0, 5.0, # flat high
1.0, 5.0, 1.0, 5.0, 1.0], # oscillating
})
clusters = pts.kmedoids(df, k=3, method="dtw")
# Returns: DataFrame with [unique_id, cluster]
K-NN classification
import polars as pl
import polars_ts as pts
train = pl.DataFrame({
"unique_id": ["t1"] * 4 + ["t2"] * 4,
"y": [1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0],
"label": ["low"] * 4 + ["high"] * 4,
})
test = pl.DataFrame({
"unique_id": ["x1"] * 4,
"y": [1.0, 1.0, 1.0, 1.1],
})
predictions = pts.knn_classify(train, test, k=1, method="dtw")
# Returns: DataFrame with [unique_id, predicted_label]
Mann-Kendall trend test
import polars as pl
import polars_ts as pts
df = pl.DataFrame({
"group": ["A"] * 10 + ["B"] * 10,
"y": list(range(10)) + [10 - x for x in range(10)],
})
result = df.group_by("group").agg(
pts.mann_kendall(pl.col("y")).alias("trend"),
pts.sens_slope(pl.col("y")).alias("slope"),
)
Seasonal decomposition
import polars as pl
import polars_ts as pts
df = pl.DataFrame({
"unique_id": ["A"] * 48,
"ds": list(range(48)),
"y": [10 + 5 * (i % 12 > 5) + 0.5 * i for i in range(48)],
})
### Seasonal decomposition
```python
import polars as pl
import polars_ts as pts
df = pl.DataFrame({
"unique_id": ["A"] * 48,
"ds": list(range(48)),
"y": [10 + 5 * (i % 12 > 5) + 0.5 * i for i in range(48)],
})
result = pts.seasonal_decomposition(df, freq=12, method="additive")
CUSUM changepoint detection
import polars as pl
import polars_ts as pts
df = pl.DataFrame({
"unique_id": ["A"] * 20,
"y": [1.0] * 10 + [5.0] * 10,
})
result = pts.cusum(df)
Kaboudan metric
import polars as pl
from statsforecast import StatsForecast
from statsforecast.models import AutoETS, OptimizedTheta
import polars_ts as pts # noqa
df = (
pl.scan_parquet("https://datasets-nixtla.s3.amazonaws.com/m4-hourly.parquet")
.filter(pl.col("unique_id").is_in(["H1", "H2", "H3"]))
.collect()
)
sf = StatsForecast(
models=[OptimizedTheta(season_length=24), AutoETS(season_length=24)],
freq=1, n_jobs=-1,
)
res = df.pts.kaboudan(sf, block_size=200, backtesting_start=0.5, n_folds=10)
Development
git clone https://github.com/drumtorben/polars-ts.git
cd polars-ts
uv sync
uv pip install -e .
uv run pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_timeseries-0.5.0.tar.gz.
File metadata
- Download URL: polars_timeseries-0.5.0.tar.gz
- Upload date:
- Size: 328.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc3e648740498f8185b6aaf18705190b72db453a0f782bbc2098ac48c8b36b1c
|
|
| MD5 |
580fbd872cf1f291b81d5e56b93564cd
|
|
| BLAKE2b-256 |
0169c14b3bf8756a8a3d630e622c057bbaf0bc9bd396716aae753b10b8479659
|
Provenance
The following attestation bundles were made for polars_timeseries-0.5.0.tar.gz:
Publisher:
release.yml on drumtorben/polars-ts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_timeseries-0.5.0.tar.gz -
Subject digest:
fc3e648740498f8185b6aaf18705190b72db453a0f782bbc2098ac48c8b36b1c - Sigstore transparency entry: 1328164506
- Sigstore integration time:
-
Permalink:
drumtorben/polars-ts@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/drumtorben
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_timeseries-0.5.0-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: polars_timeseries-0.5.0-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 15.9 MB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01c53bab21ac4f063752b69ebfd004f7af55a4f3593c51493075414a5da9d960
|
|
| MD5 |
459d26c6f4a29f2c4f8ee093475636fb
|
|
| BLAKE2b-256 |
0403e8daeae9ea1abf49402d958873e1dc99cbb30f8bfb4257e38e0d6fa4151b
|
Provenance
The following attestation bundles were made for polars_timeseries-0.5.0-cp312-abi3-win_amd64.whl:
Publisher:
release.yml on drumtorben/polars-ts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_timeseries-0.5.0-cp312-abi3-win_amd64.whl -
Subject digest:
01c53bab21ac4f063752b69ebfd004f7af55a4f3593c51493075414a5da9d960 - Sigstore transparency entry: 1328164515
- Sigstore integration time:
-
Permalink:
drumtorben/polars-ts@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/drumtorben
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_timeseries-0.5.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: polars_timeseries-0.5.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 16.9 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12eab34f85d50d06029c395abf49afe2cb4e63ffb5ed47cd5705927884992966
|
|
| MD5 |
134ccc5876854edaaea046c6c0a591f2
|
|
| BLAKE2b-256 |
ee88821eb194f569f4557d1d4925b0e44838898af9a625c77293c123135aae2a
|
Provenance
The following attestation bundles were made for polars_timeseries-0.5.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on drumtorben/polars-ts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_timeseries-0.5.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
12eab34f85d50d06029c395abf49afe2cb4e63ffb5ed47cd5705927884992966 - Sigstore transparency entry: 1328164511
- Sigstore integration time:
-
Permalink:
drumtorben/polars-ts@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/drumtorben
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_timeseries-0.5.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: polars_timeseries-0.5.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 17.2 MB
- Tags: CPython 3.12+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a979b22acda8b8ed52bebbc4293612a07a9320af635bce3dcf91f46495fc6ec8
|
|
| MD5 |
53927798b038444ad4953d6fa60742db
|
|
| BLAKE2b-256 |
76cac6099f678b7071386933c82247c37f61bd1062050531b72123605e8d0061
|
Provenance
The following attestation bundles were made for polars_timeseries-0.5.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on drumtorben/polars-ts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_timeseries-0.5.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
a979b22acda8b8ed52bebbc4293612a07a9320af635bce3dcf91f46495fc6ec8 - Sigstore transparency entry: 1328164519
- Sigstore integration time:
-
Permalink:
drumtorben/polars-ts@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/drumtorben
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_timeseries-0.5.0-cp312-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polars_timeseries-0.5.0-cp312-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 15.7 MB
- Tags: CPython 3.12+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c730c3dc4c3d5bf440c7517b03f753d6109b59d734b8fa633f2b9f700c001a9
|
|
| MD5 |
7ed2b05ed4276ee180ed50cafb9490ff
|
|
| BLAKE2b-256 |
98cdf8133bc4c976ed38afc08147874ca43d15fcb143749a33a76400cd0349fd
|
Provenance
The following attestation bundles were made for polars_timeseries-0.5.0-cp312-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on drumtorben/polars-ts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_timeseries-0.5.0-cp312-abi3-macosx_11_0_arm64.whl -
Subject digest:
6c730c3dc4c3d5bf440c7517b03f753d6109b59d734b8fa633f2b9f700c001a9 - Sigstore transparency entry: 1328164512
- Sigstore integration time:
-
Permalink:
drumtorben/polars-ts@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/drumtorben
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file polars_timeseries-0.5.0-cp312-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: polars_timeseries-0.5.0-cp312-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 16.4 MB
- Tags: CPython 3.12+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7b74f8c611792a74d9de15e35667ce1f1980e9acd9f240536421bfd32474e94
|
|
| MD5 |
b91bcb0335d99ff57a00e90aa4933400
|
|
| BLAKE2b-256 |
e4d0af9561edebdce4e88019b4892bab6c7c9778b9928a1859a3071c7a633b3d
|
Provenance
The following attestation bundles were made for polars_timeseries-0.5.0-cp312-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on drumtorben/polars-ts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
polars_timeseries-0.5.0-cp312-abi3-macosx_10_12_x86_64.whl -
Subject digest:
c7b74f8c611792a74d9de15e35667ce1f1980e9acd9f240536421bfd32474e94 - Sigstore transparency entry: 1328164507
- Sigstore integration time:
-
Permalink:
drumtorben/polars-ts@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/drumtorben
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b14dc974323196fbc8dd9e0282f8dd6b70aed3c4 -
Trigger Event:
push
-
Statement type: