Skip to main content

polars-tsfresh

A high-performance Polars-based reimplementation of tsfresh for time series feature extraction.

Python Version License Tests Coverage

polars-tsfresh extracts statistical features from time series data stored in Polars DataFrames. It's designed as a faster, more type-safe alternative to tsfresh, leveraging Polars' efficient columnar operations for better performance on grouped time series data.

Installation

With uv (Recommended)

uv add polars-tsfresh

With pip

pip install polars-tsfresh

Requirements

  • Python 3.12+
  • Polars >= 1.36.1

Quick Start

import polars as pl
from polars_tsfresh import extract_features

# Load your time series data
df = pl.read_csv("data.csv")
print(df.head())
# shape: (5, 5)
# ┌────────────┬─────────┬─────────┬─────────┬─────────┐
# │ date       ┆ open    ┆ high    ┆ low     ┆ close   │
# │ ---        ┆ ---     ┆ ---     ┆ ---     ┆ ---     │
# │ str        ┆ f64     ┆ f64     ┆ f64     ┆ f64     │
# ╞════════════╪═════════╪═════════╪═════════╪═════════╡
# │ 2025/12/03 ┆ 6815.29 ┆ 6862.42 ┆ 6810.43 ┆ 6849.72 │
# │ 2025/12/04 ┆ 6866.47 ┆ 6866.47 ┆ 6827.12 ┆ 6857.12 │
# │ 2025/12/05 ┆ 6866.32 ┆ 6895.78 ┆ 6858.29 ┆ 6870.40 │
# │ ...        ┆ ...     ┆ ...     ┆ ...     ┆ ...     │
# └────────────┴─────────┴─────────┴─────────┴─────────┘

Add an ID column to group by (here we're treating all data as one time series):

df = df.with_columns(pl.lit("sp500").alias("kind"))

Extract features:

features = extract_features(df, column_id="kind", column_sort="date")
print(features)
# shape: (1, 11)
# ┌────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┐
# │ kind       ┆ close__sum ┆ close__med ┆ close__mea ┆ close__len ┆ close__std ┆ close__var ┆ close__rms ┆ close__max ┆ close__abs ┆ close__min │
# │ ---        ┆ _values    ┆ ian        ┆ n          ┆ gth        ┆            ┆            ┆            ┆            ┆ _maximum   ┆            │
# │ str        ┆ ---        ┆ ---        ┆ ---        ┆ ---        ┆ ---        ┆ ---        ┆ ---        ┆ ---        ┆ ---        ┆ ---        │
# │ f64        ┆ f64        ┆ f64        ┆ f64        ┆ f64        ┆ f64        ┆ f64        ┆ f64        ┆ f64        ┆ f64        ┆ f64        │
# ╞════════════╪════════════╪════════════╪════════════╪════════════╪════════════╪════════════╪════════════╪════════════╪════════════╪════════════╡
# │ sp500      ┆ 137124.56  ┆ 6853.42    ┆ 6856.228   ┆ 20.0       ┆ 51.503     ┆ 2652.59    ┆ 6856.421   ┆ 6932.05    ┆ 6932.05    ┆ 6721.43    │
# └────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┘

The output shows features extracted for each group (in this case, one group "sp500") with features named using the column__feature convention from tsfresh.

Features

Current Minimal Feature Set

polars-tsfresh currently implements the "minimal" feature set from tsfresh, providing essential statistical measures:

Feature Description tsfresh Equivalent
mean Arithmetic mean of values tsfresh.feature_extraction.mean
median Median value tsfresh.feature_extraction.median
variance Variance (ddof=0) tsfresh.feature_extraction.variance
standard_deviation Standard deviation (ddof=0) tsfresh.feature_extraction.standard_deviation
length Number of data points tsfresh.feature_extraction.length
maximum Maximum value tsfresh.feature_extraction.maximum
minimum Minimum value tsfresh.feature_extraction.minimum
absolute_maximum Maximum absolute value tsfresh.feature_extraction.absolute_maximum
root_mean_square Root mean square (RMS) tsfresh.feature_extraction.root_mean_square
sum_values Sum of all values tsfresh.feature_extraction.sum_values

Performance Benefits

  • Polars Expressions: Uses Polars' vectorized operations for optimal performance
  • Grouped Operations: Efficiently handles multiple time series in a single DataFrame
  • Type Safety: Full type hints and static analysis support
  • Memory Efficient: Columnar operations reduce memory overhead

Roadmap

The project plans to implement comprehensive feature sets including:

  • Distribution Features: skewness, kurtosis, quantiles, entropy
  • Change & Rate Features: derivatives, trend analysis
  • Position & Extrema Features: peak detection, location analysis
  • Frequency Features: FFT coefficients, spectral analysis
  • Autocorrelation Features: time series modeling
  • Complexity Features: entropy measures, complexity estimates

See plan/tsfresh.yaml for the complete feature roadmap.

API Reference

extract_features(df, column_id, column_sort)

Extract features from a time series DataFrame.

Parameters:

  • df (pl.DataFrame): Input DataFrame containing time series data
  • column_id (str): Name of the column containing group IDs
  • column_sort (str): Name of the column to sort by (typically time/date)

Returns:

  • pl.DataFrame: DataFrame with extracted features, one row per group

Example:

features = extract_features(
    df=my_dataframe,
    column_id="stock_symbol",
    column_sort="timestamp"
)

Development

Setup

# Clone the repository
git clone https://github.com/lucidfrontier45/polars-tsfresh.git
cd polars-tsfresh

# Install with uv (includes dev dependencies)
uv sync

Testing

# Run all tests
uv run poe test

# Run specific test
uv run pytest tests/data/test_minimal.py::test_minimal

# Run with coverage
uv run pytest tests/ --cov=polars_tsfresh --cov-report=html

Code Quality

# Full quality check (linting + type checking)
uv run poe check

# Format code
uv run poe format

# Individual checks
uv run poe ruff_check    # Linting
uv run poe pyrefly_check # Type checking

Project Structure

polars-tsfresh/
├── src/polars_tsfresh/
│   ├── __init__.py      # Main API
│   └── features.py      # Feature implementations
├── tests/
│   └── data/
│       ├── test_minimal.py    # Test suite
│       ├── sp500_raw.csv      # Test data
│       └── sp500_tsfresh_features.csv  # Expected results
├── plan/
│   ├── tsfresh.yaml     # Feature definitions
│   └── dev_plan.md      # Development roadmap
└── pyproject.toml       # Project configuration

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all checks pass: uv run poe check && uv run poe test
  5. Submit a pull request

See AGENTS.md for detailed development guidelines and coding standards.

Related Projects

  • tsfresh: The original Python package for time series feature extraction
  • Polars: Fast DataFrame library powering this implementation

License

Licensed under the Apache License 2.0. See LICENSE for details.

Authors

Metadata

Release files for polars-tsfresh 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polars-tsfresh 0.1.1
File Size Uploaded Provenance
polars_tsfresh-0.1.1.tar.gz 6.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for polars-tsfresh 0.1.1
File Interpreter ABI Platform
polars_tsfresh-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / polars_tsfresh-0.1.1.tar.gz

Download URL polars_tsfresh-0.1.1.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3815a0dbb9c9acf0ccfef2f2429fe01f3b6a1fed526829034c55d1eb2a7bcd9e
BLAKE2b-256 checksum
How to use checksums
c62d104c4f96da93a513e2112295b40c938df76404f7f0da69c4f4b367fd24e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / polars_tsfresh-0.1.1-py3-none-any.whl

Download URL polars_tsfresh-0.1.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cafff3e1287f89956a5cd943b0de04d99ffea59edd4b25aee8308c1b4652318d
BLAKE2b-256 checksum
How to use checksums
446b270a165a7d3352d44f6cbcd25ff149fb184194d2b7b678bde68a3213adb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for polars-tsfresh 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page