Skip to content
cccskills
FreePublished on GitHub

polars

High-performance data manipulation with lazy/eager execution, expressions, I/O (CSV, Parquet, JSON), aggregations, joins, string/datetime ops, and pandas interop. Covers performance optimization patterns and common anti-patterns. DAAF's default DataFrame library — all pipeline code uses Polars, not pandas. Use for any DataFrame operation, reading/writing Parquet files, or migrating existing pandas code to Polars. R equivalent: tidyverse (use when execution language is R).

The English summary is being prepared. Showing the original description.

DAAF-Contribution-Community/daaf238 stars(GitHub 238 + cccskills 0)

Run score Not tested

See how to install

Files included (11)

  • SKILL.md12.4 KB
  • references/aggregations-grouping.md9.5 KB
  • references/dataframes-series.md8.6 KB
  • references/expressions.md8.6 KB
  • references/gotchas.md8.1 KB
  • references/interop.md8.8 KB
  • references/io-data.md9.5 KB
  • references/joins-concat.md7.5 KB
  • references/performance.md8.7 KB
  • references/quickstart.md6.1 KB
  • references/strings-datetime-categorical.md10.3 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Polars Skill

Polars DataFrame library for high-performance data manipulation in Python. Covers lazy/eager execution, expressions, I/O (CSV, Parquet, JSON, database), aggregations, joins, string/datetime operations, pandas/NumPy interop, and performance optimization. Use when working with Polars DataFrames, migrating from pandas, reading Parquet files, or optimizing data pipeline performance.

Comprehensive skill for high-performance data manipulation with Polars. Use decision trees below to find the right guidance, then load detailed references.

What is Polars?

Polars is a fast DataFrame library for Python (and Rust):

  • Fast: Written in Rust, optimized for modern CPUs with SIMD and parallelism
  • Lazy Evaluation: Build query plans that get optimized before execution
  • Expressive: Powerful expression API for complex transformations
  • Memory Efficient: Columnar format, streaming for larger-than-memory data
  • No Dependencies: Pure Rust core, no NumPy/Pandas required

Version Notes

This skill targets Polars 1.x (tested with 1.37.1). Key changes from 0.x:

  • apply renamed to map_elements (0.19+)
  • groupby renamed to group_by (0.19+)
  • melt renamed to unpivot (1.0+)
  • Streaming engine improvements in 1.x
  • pl.Utf8 is now pl.String (1.0+, Utf8 still works as alias)

How to Use This Skill

Reference File Structure

Each topic in ./references/ contains focused documentation:

FilePurposeWhen to Read
quickstart.mdInstallation, concepts, first DataFrameStarting with Polars
dataframes-series.mdCreation, selection, filtering, modificationBasic data manipulation
io-data.mdCSV, Parquet, JSON, database I/OLoading/saving data
expressions.mdExpression system, contexts, chainingUnderstanding Polars idioms
aggregations-grouping.mdGroupBy, window functions, statisticsSummarizing data
joins-concat.mdJoins, concatenation, pivot/unpivotCombining DataFrames
strings-datetime-categorical.mdString ops, datetime, categoricalsType-specific operations
performance.mdLazy execution, optimization, anti-patternsMaking code faster
interop.mdPandas, NumPy, PyArrow, DuckDBWorking with other tools
gotchas.mdCommon errors, anti-patterns, migrationDebugging issues

Reading Order

  1. New to Polars? Start with quickstart.md then expressions.md
  2. Coming from Pandas? Read quickstart.md, expressions.md, then interop.md
  3. Performance issues? Check performance.md first

The reference-file routing in this skill applies to advisory and brainstorming turns as much as implementation. Recommending an approach, reviewing a plan, or answering a question that touches a routed topic calls for reading the routed reference file just as much as writing code does — the reference files carry curated caveats and environment-specific constraints that this overview and general knowledge lack.

Quick Decision Trees

"I need to get started"

Getting started?
├─ Install Polars → ./references/quickstart.md
├─ Create first DataFrame → ./references/quickstart.md
├─ Understand lazy vs eager → ./references/quickstart.md
├─ Learn expression syntax → ./references/expressions.md
└─ Coming from Pandas → ./references/interop.md

"I need to load or save data"

Loading/saving data?
├─ Read CSV file → ./references/io-data.md
├─ Read Parquet (recommended) → ./references/io-data.md
├─ Read JSON/NDJSON → ./references/io-data.md
├─ Read from database → ./references/io-data.md
├─ Read multiple files (glob) → ./references/io-data.md
├─ Write to file → ./references/io-data.md
└─ Larger-than-memory data → ./references/performance.md

"I need to filter or select data"

Filtering/selecting?
├─ Select columns by name → ./references/dataframes-series.md
├─ Select by pattern/regex → ./references/dataframes-series.md
├─ Select by data type → ./references/dataframes-series.md
├─ Filter rows by condition → ./references/dataframes-series.md
├─ Filter with multiple conditions → ./references/dataframes-series.md
├─ Handle null values → ./references/dataframes-series.md
└─ Add/modify columns → ./references/dataframes-series.md

"I need to aggregate or group data"

Aggregating data?
├─ Basic statistics (sum, mean, etc.) → ./references/aggregations-grouping.md
├─ Group by columns → ./references/aggregations-grouping.md
├─ Multiple aggregations → ./references/aggregations-grouping.md
├─ Window functions (over) → ./references/aggregations-grouping.md
├─ Rolling/moving averages → ./references/aggregations-grouping.md
├─ Cumulative operations → ./references/aggregations-grouping.md
└─ Ranking within groups → ./references/aggregations-grouping.md

"I need to combine DataFrames"

Combining data?
├─ Join two DataFrames → ./references/joins-concat.md
├─ Left/right/outer join → ./references/joins-concat.md
├─ Anti-join (not in) → ./references/joins-concat.md
├─ Concatenate vertically → ./references/joins-concat.md
├─ Pivot (long to wide) → ./references/joins-concat.md
└─ Unpivot/melt (wide to long) → ./references/joins-concat.md

"I need better performance"

Performance issues?
├─ Use lazy evaluation → ./references/performance.md
├─ Avoid row iteration → ./references/performance.md
├─ Reduce memory usage → ./references/performance.md
├─ Process large files → ./references/performance.md
├─ Optimize query plan → ./references/performance.md
└─ Common anti-patterns → ./references/performance.md

"Something isn't working"

Having issues?
├─ Type errors → ./references/gotchas.md
├─ Null handling → ./references/gotchas.md
├─ Expression context errors → ./references/gotchas.md
├─ String operations → ./references/strings-datetime-categorical.md
├─ Date parsing issues → ./references/strings-datetime-categorical.md
├─ Performance problems → ./references/gotchas.md
├─ Pandas migration issues → ./references/gotchas.md
├─ Memory errors → ./references/gotchas.md
└─ General troubleshooting → ./references/gotchas.md

File-First Execution in Research Workflows

Important: In data research pipelines (see CLAUDE.md), Polars transformations are executed through script files, not interactively. This ensures auditability and reproducibility.

The pattern:

  1. Write transformation code to scripts/stage{N}_{type}/{step}_{task-name}.py
  2. Execute via Bash with automatic output capture wrapper script
  3. Validation results get automatically embedded in scripts as comments
  4. If failed, create versioned copy for fixes

Closely read agent_reference/SCRIPT_EXECUTION_REFERENCE.md for the mandatory file-first execution protocol covering complete code file writing, output capture, and file versioning rules.

See:

  • agent_reference/SCRIPT_EXECUTION_REFERENCE.md — Script execution protocol and format with validation

The examples below show Polars syntax. In research workflows, wrap them in scripts following the file-first pattern.


Quick Reference

Essential Import

import polars as pl
import polars.selectors as cs  # For column selection by type

Lazy vs Eager (One-Liner)

# Eager: immediate execution
df = pl.read_csv("data.csv")

# Lazy: deferred, optimized execution (preferred for large data)
lf = pl.scan_csv("data.csv")
df = lf.collect()  # Execute when ready

Core Expression Patterns

# Select columns
df.select("a", "b")
df.select(pl.col("a"), pl.col("b"))
df.select(pl.all().exclude("id"))

# Filter rows
df.filter(pl.col("a") > 10)
df.filter((pl.col("a") > 10) & (pl.col("b") == "x"))

# Add/modify columns
df.with_columns(
    (pl.col("a") * 2).alias("a_doubled"),
    pl.col("b").str.to_uppercase().alias("b_upper")
)

# Conditional column
df.with_columns(
    pl.when(pl.col("a") > 10)
      .then(pl.lit("high"))
      .otherwise(pl.lit("low"))
      .alias("category")
)

# Group and aggregate
df.group_by("category").agg(
    pl.col("value").sum().alias("total"),
    pl.col("value").mean().alias("average"),
    pl.len().alias("count")
)

Essential Functions

FunctionPurpose
pl.col("name")Reference a column
pl.lit(value)Literal value
pl.all()All columns
pl.exclude("col")All except specified
pl.len()Row count
pl.when().then().otherwise()Conditional logic
.alias("name")Rename result
.cast(pl.Int64)Convert type

Common Data Types

TypeDescription
pl.Int64, pl.Int32Integers
pl.Float64, pl.Float32Floats
pl.String (or pl.Utf8)Strings
pl.BooleanTrue/False
pl.Date, pl.DatetimeDates and timestamps
pl.DurationTime differences
pl.CategoricalCategorical strings
pl.ListList of values
pl.StructNamed fields

Quick Cheatsheet

# I/O
df = pl.read_csv/parquet/json("file")
lf = pl.scan_csv/parquet/ndjson("file")  # Lazy
df.write_csv/parquet/json("file")

# Selection
df.select("a", "b")
df.select(cs.numeric())  # By type

# Filtering
df.filter(pl.col("a") > 1)

# Aggregation
df.group_by("key").agg(pl.col("val").sum())

# Joining
df1.join(df2, on="key", how="left")

# Sorting
df.sort("col", descending=True)

# Lazy execution
lf.collect()  # Run query
lf.explain()  # Show plan

Topic Index

TopicReference File
Installation./references/quickstart.md
DataFrame Creation./references/quickstart.md
Lazy vs Eager./references/quickstart.md
Column Selection./references/dataframes-series.md
Row Filtering./references/dataframes-series.md
Adding Columns./references/dataframes-series.md
CSV Files./references/io-data.md
Parquet Files./references/io-data.md
Database Connections./references/io-data.md
Expressions./references/expressions.md
Method Chaining./references/expressions.md
Contexts./references/expressions.md
GroupBy./references/aggregations-grouping.md
Window Functions./references/aggregations-grouping.md
Rolling Windows./references/aggregations-grouping.md
Joins./references/joins-concat.md
Concatenation./references/joins-concat.md
Pivot/Unpivot./references/joins-concat.md
String Operations./references/strings-datetime-categorical.md
Datetime Handling./references/strings-datetime-categorical.md
Categorical Data./references/strings-datetime-categorical.md
Query Optimization./references/performance.md
Memory Management./references/performance.md
Anti-Patterns./references/performance.md
Pandas Conversion./references/interop.md
NumPy Integration./references/interop.md
DuckDB Integration./references/interop.md
Type Errors./references/gotchas.md
qcut Label Gotcha./references/gotchas.md
Null Handling Issues./references/gotchas.md
Expression Context Errors./references/gotchas.md
Performance Anti-Patterns./references/gotchas.md
Migration from Pandas./references/gotchas.md
Memory Issues./references/gotchas.md

Citation

When this library is used as a primary analytical tool, include in the report's Software & Tools references:

Vink, R. et al. Polars: Blazingly fast DataFrames [Computer software]. https://pola.rs/

Cite when: Polars is the core data processing engine for the analysis (typically always true in DAAF pipelines). Do not cite when: Only used for trivial file I/O in a script primarily using another tool.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Guide for creating DAAF agent definition files. Covers 12-section template, hook registration, skills-in-frontmatter, integration checklist. Use when adding or revising agents. For SKILL.md files, use skill-authoring instead.

The English summary is being prepared. Showing the original description.

DAAF-Contribution-Community/daaf238Updated Oct 17, 2026

Researcher-facing analytic triangulation ("creative verification") for stress-testing provisional findings and designing pre-specified challenges before an analysis runs. Turns a researcher's concern or focal claim into competing explanations, bounded discriminating tests, audited diagnostic artifacts, and evidence-calibrated interpretations in a hypothesis/evidence ledger — behavioral, output-level verification replacing line-by-line code review. Covers 12 challenge families organized by Shadish-Cook-Campbell validity type, named sensitivity statistics, pre-committed interpretation rules, anti-fishing guardrails, and interactive diagnostic-artifact QA. Use in Ad Hoc Collaboration to verify, challenge, or stress-test a result, or to design discriminating tests before an analysis runs. Not code-change verification (verify skill / code review) and not final adjudication or re-execution (data-verifier, Reproducibility Verification) — prospective, hypothesis-driven challenge design of analytic claims.

The English summary is being prepared. Showing the original description.

DAAF-Contribution-Community/daaf238Updated Oct 17, 2026

In-situ smoke testing that verifies a LIVE DAAF deployment functions end-to-end in whatever provider route it is configured for. Auto-detects the active install route (anthropic-subscription, openrouter, chatgpt-subscription shim, openai-api shim) and runs tiered probes: Tier 0 free preflight (route/env coherence, hooks, statuslines, shim health); Tier 1 one live round-trip (~cents); Tier 2 a six-probe functional battery (dispatch, coding, web, skill loading, isolation-strip, nested-dispatch deny); Tier D a zero-cost deterministic battery (bats, Pester, lint, safety-hook tests). Use after install, after a rebuild or update, after any provider/config change (new API key, model remap, shim change), for pre-release validation, or when asked "is my install working" or to "smoke test the deployment/config." Requires the DAAF_DEV=1 dev image; a contributor tool, not end-user-facing. NOT DAAFBench (model behavioral-adherence evaluation under benchmarks/) and NOT scripts/smoke_tests/ (R/Python library-package smoke tests).

The English summary is being prepared. Showing the original description.

DAAF-Contribution-Community/daaf238Updated Oct 17, 2026

Operational framework for the DAAF orchestrator. Defines engagement modes, confirmation protocol, subagent dispatch, context budget, and reference-loading. Loaded exclusively by the orchestrator — not for subagents or user questions.

The English summary is being prepared. Showing the original description.

DAAF-Contribution-Community/daaf238Updated Oct 17, 2026

Data science methodology and method-selection routing for quantitative research. Covers EDA, data validation, descriptive analysis, causal inference (IV, DiD, RD, synthetic control), clustering/PCA/UMAP, supervised ML, geospatial analysis, network analysis, and visualization design. Contains the canonical method-to-library routing tree, routed by execution language — Python: statsmodels (OLS/GLM/time series), pyfixest (FE/DiD), linearmodels (RE/GMM/SUR), svy (complex surveys), scikit-learn (clustering/prediction ML), geopandas (spatial), igraph (network analysis); R: r-stats (OLS/GLM/time series), fixest (FE/DiD), plm (panel/RE/IV), survey-r (complex surveys), tidymodels (ML), sf-terra (spatial), igraph-r (network analysis). Load the routed tool-specific skill before giving tool-specific advice or writing code — library skills encode environment constraints and curated caveats absent from general knowledge.

The English summary is being prepared. Showing the original description.

DAAF-Contribution-Community/daaf238Updated Oct 17, 2026

Interpretation guidance for Urban Institute Education Data Portal datasets. The Portal is a curation layer over federal data: lowercase variable names, integer-encoded categoricals, standardized missing codes (-1 missing, -2 not applicable, -3 suppressed). Covers year definitions, grade encoding (grade=-1 is Pre-K, not missing), suppression rates, ODC-By licensing, and cross-source join identifiers. Load before analyzing any Portal data. Routes to source-specific deep-dive skills for individual datasets.

The English summary is being prepared. Showing the original description.

DAAF-Contribution-Community/daaf238Updated Oct 17, 2026

See all skills by DAAF-Contribution-Community

Report a problem with this skill