Skip to main content

Yet Another Sequence Analytics Toolkit - A modern Python library for sequence analysis with polars

Project description

yasqat

Yet Another Sequence Analytics Toolkit

PyPI Python License: MIT

A modern Python library for categorical sequence analysis, built on polars. Designed for social-science and life-course research — labour-market trajectories, health pathways, educational histories, and similar domains.

Inspired by TraMineR (R) and TanaT (Python).

Features

  • Polars-native data structuresAlphabet, StateSequence, SequencePool for fast sequence manipulation. Interval-shaped input is sampled into a StateSequence via StateSequence.from_intervals(df, time_points=...).
  • Distance metrics — Optimal Matching, Hamming, LCS, LCP, RLCP, DTW, SoftDTW, Chi², Euclidean, DHD, TWED, and OM variants (OMloc, OMspell, OMstran, NMS, NMSMST, SVRspell), with convenience length/similarity wrappers for LCS, LCP, and RLCP
  • Substitution costs — constant, transition-rate, indels, indelslog, future (chi-squared), features (Gower distance)
  • Clustering — PAM (k-medoids) with .predict(), CLARA, hierarchical (scipy linkage); parallel pairwise distance computation via n_jobs
  • Cluster quality — silhouette (ASW), Point Biserial, Hubert's Gamma, R², PAM range analysis, distance to center, representative extraction
  • Discrepancy analysis — pseudo-ANOVA with permutation tests, multi-factor discrepancy, dissimilarity trees
  • Descriptive statistics — entropy, transition rates, complexity, turbulence, spell counts, visited states, modal states (with time granularity), sequence frequencies, log-probabilities, subsequence counts (with state filtering and log-transform)
  • Normative indicators — volatility, precarity, insecurity, degradation, badness, integration (per-state), proportion positive
  • Subsequence mining — frequent subsequence discovery with support thresholds and minimum length, returned as polars DataFrames
  • Plot-library agnostic — every method returns a polars DataFrame, so users can plot with their tool of choice (matplotlib, altair, observable, …). Alphabet.colors is exposed for consistent palette use.
  • Filtering — length, time, state, and starts-with sequence filtering
  • Data I/O — CSV, Parquet, and DataFrame loading (Hive/Spark/Arrow interop) with automatic type inference
  • Synthetic data — Markov-chain and financial trajectory generators

Installation

pip install yasqat

Quick start

from yasqat.io import load_csv

# Load sequences from CSV (also: load_dataframe, load_parquet)
pool = load_csv("trajectories.csv", id_col="id", time_col="time", state_col="state")

# Compute pairwise distances and cluster
dm = pool.compute_distances(method="om", indel=1.0, n_jobs=4)

from yasqat.clustering import pam_clustering
result = pam_clustering(dm, n_clusters=4)

# Descriptive statistics
from yasqat.statistics import longitudinal_entropy, turbulence
longitudinal_entropy(pool)
turbulence(pool)

# Plot with your library of choice — yasqat methods return polars DataFrames
state_distribution = pool.to_state_sequence().state_per_sequence(proportion=True)
# Hand `state_distribution` to matplotlib, altair, plotnine, etc.

Development

# Clone and install with dev dependencies
git clone https://github.com/rexarski/yasqat.git
cd yasqat
uv venv && source .venv/bin/activate  # or activate.fish
uv pip install -e ".[dev]"

# Run tests
uv run pytest

# Lint and format
uv run ruff check src/ tests/
uv run ruff format src/ tests/

# Type check
uv run mypy src/yasqat/

License

MIT License — see LICENSE for details.

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yasqat-0.4.0.tar.gz (102.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yasqat-0.4.0-py3-none-any.whl (85.5 kB view details)

Uploaded Python 3

File details

Details for the file yasqat-0.4.0.tar.gz.

File metadata

  • Download URL: yasqat-0.4.0.tar.gz
  • Upload date:
  • Size: 102.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for yasqat-0.4.0.tar.gz
Algorithm Hash digest
SHA256 901e2c4c0a22ab278f1f80c0ec00ea0a6a4455636d5d9bc1d5e170f15a02823b
MD5 c074494be057f5822c4efd96b0956cc9
BLAKE2b-256 2f26b8c8532a78feb29c27b896105355eb962b78dc6c1faec16d509f49097566

See more details on using hashes here.

File details

Details for the file yasqat-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: yasqat-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 85.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for yasqat-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 440290c41ef6a0b1961f2b5fa8662f7e05f61b47fcab53773ff9a78f06658b2d
MD5 4b7c96dca9ee9671898bc809fcd29c5d
BLAKE2b-256 4f3ea79dd7e0cd78f01d7f44bea65253fe3e271b60175b4ef3709c2871aef8b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page