agentleFS
dtunaidtunai/agent-skills-for-compute/skills/polars/SKILL.md

polars

Skill8 starsChanged 8 months agoMITView on GitHub

Polars DataFrame library with GPU acceleration via RAPIDS cuDF — lazy evaluation, expressions API, and high-performance data transformations

  • Installs packages

21 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use deeptools, dnanexus-integration and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • garri333Skill

    deeptools

    NGS analysis toolkit. BAM to bigWig conversion, QC (correlation, PCA, fingerprints), heatmaps/profiles (TSS, peaks), for ChIP-seq, RNA-seq, ATAC-seq visualization.

    Also in 12 projects that use this

  • garri333Skill

    dnanexus-integration

    DNAnexus cloud genomics platform. Build apps/applets, manage data (upload/download), dxpy Python SDK, run workflows, FASTQ/BAM/VCF, for genomics pipeline development and execution.

    Also in 12 projects that use this

  • yf8578Skill

    usfiscaldata

    Query the U.S. Treasury Fiscal Data API for federal financial data including national debt, government spending, revenue, interest rates, exchange rates, and savings bonds. Access 54 datasets and 182 data tables with no API key required. Use when working with U.S. federal fiscal data, national debt tracking (Debt to the Penny), Daily Treasury Statements, Monthly Treasury Statements, Treasury securities auctions, interest rates on Treasury securities, foreign exchange rates, savings bonds, or any U.S. government financial statistics.

    Also in 7 projects that use this

  • tondevrelSkill

    simpy

    A process-based discrete-event simulation framework. Use for modeling queuing systems, supply chains, manufacturing processes, network simulation, project management, and any system where events occur at specific points in time. Load when working with discrete event simulation, process modeling, resource allocation, virtual time, simpy.Environment, simpy.Resource, or event-driven simulation.

    Also in 10 projects that use this

  • +8 more from garri333

The file

Files
SKILL.md

Polars GPU Skill

Fast DataFrame library with GPU acceleration via RAPIDS cuDF engine. Lazy evaluation, expressions API, and optimized query execution.

Official Sources:

Installation

# CPU-only Polars
pip install polars

# With GPU support
pip install polars[gpu]

# CUDA 11 (RAPIDS v25.06 and earlier)
pip install polars cudf-polars-cu11

GPU Requirements:

  • NVIDIA Volta™ or newer (compute capability 7.0+)
  • CUDA 12 (CUDA 11 support ends with RAPIDS v25.06)
  • Linux or WSL2

Quick Start

import polars as pl

# DataFrame (eager)
df = pl.DataFrame({"name": ["Alice", "Bob"], "age": [25, 30]})
df.filter(pl.col("age") > 28)

# LazyFrame (deferred)
lf = pl.LazyFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
result = lf.filter(pl.col("a") > 1).collect()      # CPU
result = lf.filter(pl.col("a") > 1).collect(engine="gpu")  # GPU

GPU Execution

# CPU vs GPU
df = lf.collect()                    # CPU
df = lf.collect(engine="gpu")        # GPU

# Config: device, raise_on_fail, verbose
df = lf.collect(engine=pl.GPUEngine(device=1, raise_on_fail=True))

# Peak performance: export POLARS_GPU_ENABLE_CUDA_MANAGED_MEMORY=0

Expressions

# Column selection
pl.col("name")                        # Single
pl.col("a", "b", "c")                 # Multiple
pl.col("^value_.*$")                  # Regex
pl.col(pl.Int64)                      # By dtype

# Arithmetic & comparisons
pl.col("a") + 10
pl.col("age") > 30
pl.col("value").is_between(10, 20)

# Aggregations
pl.col("value").sum()
pl.col("value").mean()
df.group_by("category").agg([
    pl.col("value").sum().alias("total"),
    pl.col("id").count().alias("count")
])

String, temporal, list operations

pl.col("text").str.to_lowercase() pl.col("text").str.contains("pattern") pl.col("date").dt.year() pl.col("timestamp").dt.truncate("1h") pl.col("items").list.sum() pl.col("items").list.explode()


## I/O Operations

```python
# CSV, Parquet, JSON
df = pl.read_csv("data.csv")
lf = pl.scan_parquet("data.parquet")  # Lazy (recommended)
df = pl.read_ndjson("data.ndjson")

# Write
df.write_csv("output.csv")
df.write_parquet("output.parquet", compression="snappy")
df.write_ndjson("output.ndjson")

# Multiple files
df = pl.scan_parquet("data/*.parquet").collect()

Lazy API and Query Optimization

# Build query
lf = pl.scan_parquet("data.parquet")
query = (
    lf
    .filter(pl.col("status") == "active")  # Predicate pushdown
    .select(["id", "name", "value"])       # Projection pushdown
    .group_by("name")
    .agg(pl.col("value").sum())
)

print(query.explain(optimized=True))  # View optimized plan
result = query.collect()              # Execute

Data Transformations

# Filter, select, add columns
df.filter((pl.col("age") > 30) & (pl.col("city") == "NYC"))
df.select(["name", "age"])
df.with_columns((pl.col("price") * pl.col("quantity")).alias("total"))

# Joins
df1.join(df2, on="id", how="left")
df1.join(df2, on=["id", "date"], how="inner")

# Group by and aggregate
df.group_by(["category", "region"]).agg([
    pl.col("value").sum().alias("total"),
    pl.col("id").count().alias("count")
])

# Window functions
df.with_columns(pl.col("value").sum().over("category").alias("total"))
df.with_columns(pl.col("value").rolling_mean(window_size=3).alias("ma"))

# Pivot/melt
df.pivot(values="value", index="date", columns="category")
df.melt(id_vars=["id"], value_vars=["a", "b", "c"])

GPU-Specific Considerations

Supported: LazyFrame, CSV/Parquet/NDJSON, numeric/string/datetime ops, aggregations, joins, window functions

Not Supported: Eager API, streaming, Date/Categorical/Enum types, UDFs

Best Performance: Grouped aggregations, complex joins, compute-heavy ops on large datasets (up to ~50-100 GiB)

Memory: Set POLARS_GPU_ENABLE_CUDA_MANAGED_MEMORY=0 for peak performance

SQL Interface

result = pl.sql("SELECT a * 2 FROM self WHERE a > 1", self=lf).collect()
result = pl.sql("SELECT category, SUM(value) FROM data GROUP BY category",
                data=pl.scan_parquet("data.parquet")).collect(engine="gpu")

Type System

Types: Int8/16/32/64, UInt8/16/32/64, Float32/64, String, Binary, Date, Datetime, Duration, Time, List, Struct, Array, Boolean, Categorical, Enum

# Cast
df.with_columns(pl.col("value").cast(pl.Float64))
pl.read_csv("data.csv", dtypes={"id": pl.Int64})

Performance Tips

  1. Use Lazy API (scan_* not read_*)
  2. GPU for compute-heavy ops (aggregations, joins)
  3. Set POLARS_GPU_ENABLE_CUDA_MANAGED_MEMORY=0
  4. Select columns early, filter early
  5. Use appropriate types

Common Patterns

# GPU ETL pipeline
lf = pl.scan_parquet("raw/*.parquet")
result = (
    lf
    .filter(pl.col("status") == "active")
    .with_columns((pl.col("price") * pl.col("quantity")).alias("total"))
    .group_by(["hour", "category"])
    .agg(pl.col("total").sum().alias("revenue"))
).collect(engine="gpu")
result.write_parquet("output.parquet")

References

  • Fundamentals - DataFrame, LazyFrame, Series, core concepts
  • Lazy Query Optimization - Query plans, optimizations, predicate/projection pushdown
  • GPU Engine - cuDF integration, configuration, performance tuning
  • I/O Operations - CSV, Parquet, JSON, cloud storage, multi-file reads
  • Expressions API - Expression syntax, namespaces, aggregations, window functions

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.