Ml4t Polars Patterns logo

Ml4t Polars Patterns

Organization
ml4t
ml4t-polars-patterns

Polars-first data processing patterns for financial data. Use when writing efficient grouped, windowed, or lazy-evaluated data transformations.

Overview

Publisherml4t
Repositoryskills
Skill nameml4t-polars-patterns
Stars
45
Forks
13
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by ml4t on GitHub. Read the source before you install it.

Installation

Install the Ml4t Polars Patterns AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/ml4t/skills/tree/main/infrastructure/polars-patterns
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ml4t/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/infrastructure/polars-patterns .claude/skills/ml4t-polars-patterns
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Ml4t Polars Patterns in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Ml4t Polars Patterns on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Ml4t Polars Patterns is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Polars Patterns for Quant Finance

Pandas groupby-apply with Python functions is 10-100x slower than Polars lazy expressions with .over(). For financial data - where most operations are per-symbol rolling computations - the performance gap determines whether your pipeline takes minutes or hours.

The Problem

A typical quant workflow: load 500 symbols of daily data (2M rows), compute 20-day rolling features per symbol, cross-sectional rank, then join with labels. In pandas with groupby().apply(), this takes 45 seconds and 8 GB of RAM. The same logic in Polars lazy mode takes 2 seconds and 800 MB. The difference is not optimization - it is a fundamentally different execution model.

The Pattern

WRONG

python
import pandas as pd

# Pandas: iterative groupby-apply - Python loop per group
df = pd.read_parquet("prices.parquet")

# Slow: Python function called once per symbol
def compute_features(group):
    group["momentum"] = group["close"].pct_change(20)
    group["volatility"] = group["close"].pct_change().rolling(20).std()
    group["rank"] = group["momentum"].rank(pct=True)
    return group

df = df.groupby("symbol").apply(compute_features)  # Python loop: 500 iterations

CORRECT

python
import polars as pl

# Polars: vectorized expressions with .over() - no Python loops
df = (
    pl.scan_parquet("prices.parquet")
    .with_columns(
        momentum=pl.col("close").pct_change(20).over("symbol"),
        volatility=pl.col("close").pct_change().rolling_std(20).over("symbol"),
    )
    .with_columns(
        rank=pl.col("momentum").rank().over("timestamp"),  # cross-sectional
    )
    .collect()
)
# Same result, 10-50x faster, fraction of memory

Key Pattern: .over() for Per-Symbol Operations

.over("symbol") is the Polars equivalent of groupby("symbol").transform(), but it runs as a vectorized expression - no Python callback, no per-group overhead.

python
df.with_columns(
    # Time-series operations per symbol
    ret_1d=pl.col("close").pct_change().over("symbol"),
    sma_20=pl.col("close").rolling_mean(20).over("symbol"),
    zscore=(
        (pl.col("close") - pl.col("close").rolling_mean(60).over("symbol"))
        / pl.col("close").rolling_std(60).over("symbol")
    ),
    # Cross-sectional operations per timestamp
    cs_rank=pl.col("close").pct_change().rank().over("timestamp"),
)

Lazy Evaluation for Large Data

python
# Lazy: build query plan, execute once - Polars optimizes the plan
result = (
    pl.scan_parquet("data/*.parquet")          # lazy: reads nothing yet
    .filter(pl.col("timestamp") >= "2020-01-01")  # pushed down to parquet
    .with_columns(ret=pl.col("close").pct_change().over("symbol"))
    .filter(pl.col("symbol").is_in(universe))     # pushed down
    .collect()                                     # executes optimized plan
)

Benefits: predicate pushdown reads only needed row groups from parquet, projection pushdown reads only needed columns, parallelism across cores automatically.

Temporal Joins (As-Of Join)

Joining features to labels by exact timestamp misses rows. join_asof finds the nearest preceding match:

python
# Join features (computed at varying times) to labels (fixed schedule)
labels_with_features = labels.join_asof(
    features.sort("timestamp"),
    on="timestamp",
    by="symbol",
    strategy="backward",  # most recent feature <= label timestamp
)

Guardrails

  • Always use pl.scan_parquet() (lazy) over pl.read_parquet() (eager) for files larger than 100 MB
  • Never use .map_elements() (Python UDF) when a native expression exists - 10-100x penalty
  • Single .with_columns() call for parallel computations - do not chain separate calls
  • Convert to pandas only at visualization boundaries (df.to_pandas() for matplotlib/seaborn)
  • Sort before .rolling_*() and .over() - Polars does not implicitly sort

Checklist

  • Using pl.scan_parquet() for files > 100 MB (lazy evaluation)
  • Per-symbol operations use .over("symbol"), not groupby-apply
  • Cross-sectional operations use .over("timestamp")
  • All rolling features in a single .with_columns() call
  • No .map_elements() where native expressions exist
  • Pandas conversion only at visualization boundary

Frequently asked questions

What does the Ml4t Polars Patterns AI skill do?

Polars-first data processing patterns for financial data. Use when writing efficient grouped, windowed, or lazy-evaluated data transformations.

Why use Ml4t Polars Patterns on TypingMind?

Because you install it once and use it with any model. Ml4t Polars Patterns is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Ml4t Polars Patterns in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/ml4t/skills/tree/main/infrastructure/polars-patterns. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Ml4t Polars Patterns?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Ml4t Polars Patterns?

As many as you like. As long as a model supports skills, you can use Ml4t Polars Patterns with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Ml4t Polars Patterns AI skill free?

Yes. It is published on GitHub by ml4t under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇