Skip to content

Polars ts

polars_ts

compute_pairwise_distance(input1, input2, method='dtw', **kwargs)

Compute pairwise distance between time series using the specified method.

This is the unified entry point for all distance metrics. It dispatches to the appropriate Rust implementation based on the method parameter.

Parameters:

Name Type Description Default
input1 DataFrame

DataFrame with columns unique_id and y (univariate) or unique_id and multiple value columns (multivariate).

required
input2 DataFrame

DataFrame with the same schema as input1.

required
method Literal['dtw', 'ddtw', 'wdtw', 'msm', 'erp', 'lcss', 'twe', 'sbd', 'frechet', 'edr', 'dtw_multi', 'msm_multi']

The distance metric to use. One of:

Univariate:

  • dtw — Dynamic Time Warping (default). Accepts dtw_method (standard, sakoe_chiba, itakura, fast) and param.
  • ddtw — Derivative DTW. No extra parameters.
  • wdtw — Weighted DTW. Accepts g (weight penalty, default 0.05).
  • msm — Move-Split-Merge. Accepts c (cost, default 1.0).
  • erp — Edit Distance with Real Penalty. Accepts g (gap value, default 0.0).
  • lcss — Longest Common Subsequence. Accepts epsilon (threshold, default 1.0).
  • twe — Time Warp Edit Distance. Accepts nu (stiffness, default 0.001) and lambda_ (edit penalty, default 1.0).

Multivariate:

  • dtw_multi — Multivariate DTW. Accepts metric (manhattan or euclidean).
  • msm_multi — Multivariate MSM. Accepts c (cost, default 1.0).
'dtw'
**kwargs Any

Method-specific parameters (see above).

{}

Returns:

Type Description
DataFrame

A DataFrame with columns unique_id_1, unique_id_2, and the distance column.

Raises:

Type Description
ValueError

If an unknown method or unexpected keyword argument is passed.

Examples:

>>> compute_pairwise_distance(df, df, method="dtw")
>>> compute_pairwise_distance(df, df, method="lcss", epsilon=0.5)
>>> compute_pairwise_distance(df, df, method="dtw", dtw_method="sakoe_chiba", param=3.0)

mann_kendall(expr)

Mann-Kendall test for expression.

sens_slope(expr)

Sen's slope estimator (median of pairwise slopes).