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), per-sequence state distributions
  • Normative indicators — volatility, objective (label-free) volatility, precarity, insecurity, degradation, badness, integration (per-state), proportion positive
  • Subsequence mining — frequent subsequence discovery with support thresholds and minimum length, plus sequential association rules (confidence, lift, leverage, conviction), 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_json, load_parquet).
# Every loader returns a SequencePool, the analysis container. Default column
# names are id/time/state; pass config=SequenceConfig(...) to override.
pool = load_csv("trajectories.csv")

# 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, 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/

Project conventions

Development guidance lives in CLAUDE.md. This repo follows Matt Pocock's agent-skills setup:

  • Issues are tracked in-repo as markdown under .scratch/ (single source of truth) — see .scratch/README.md for the board.
  • Agent configuration (issue tracker, triage labels, domain docs) lives in docs/agents/.
  • Architecture decisions are recorded as ADRs in docs/adr/.

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.5.0.tar.gz (109.1 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.5.0-py3-none-any.whl (88.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: yasqat-0.5.0.tar.gz
  • Upload date:
  • Size: 109.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.5.0.tar.gz
Algorithm Hash digest
SHA256 5d554b8c1d7a575c161c80273236cc99dc2b7e262f1e9f6f2842e0507512709a
MD5 4a4e432d14fc037aa66233096a6905e4
BLAKE2b-256 8961402eaa00965a4d56853e8c2a67a76e4cd39531c24be9f72ffe9d51e6f76b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yasqat-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 88.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ca2f7ec26edefcb72a536acc70a63513be6c359cabfafe25c1af638664a98e7
MD5 7906d353d146f63e4f6253fc1b49e00e
BLAKE2b-256 c7d8ed701eec5ba6b15188b52f2c5a9e2fae8b050aa1092b216af03f3ae95cf6

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