polars
Skill81 starsChanged 5 months agoMITView on GitHub
Write fast, idiomatic Polars in Python using the lazy API, and answer natural-language questions about data in one shot. Use this skill whenever a task involves loading, querying, transforming, aggregating, joining, or analyzing tabular data (CSV, Parquet, NDJSON, or DataFrames). top-k, trends, period-over-period, distributions, time series, share-of-total, or writing, debugging, or speeding up Polars code, or translating pandas to Polars. Applies even when the user doesn't say "Polars," and is the default for Python data work when no dataframe library is specified. Covers expressions, window functions, group-bys, joins, the streaming engine for larger-than-memory data, and pandas migration. Not for Polars Cloud, On-Prem, distributed, or GPU workloads.
10 other projects use a version of this.
Adopted by
Most recently taken up by
- BrightGold70/skillstheir own version, first seen Sep 29, 2026
- DAAF-Contribution-Community/daaftheir own version, first seen Aug 9, 2026
- Barrios88/barrios-skillstheir own version, first seen Jun 12, 2026
- LeonChaoX/qinyan-academic-skillstheir own version, first seen Mar 13, 2026
- qinyan-ai/qinyan-academic-skillstheir own version, first seen Mar 13, 2026
- JunMA98/Computer-science-claude-skillstheir own version, first seen Mar 11, 2026
Used with
Projects with it also use pydicom, simpy 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.
tondevrelSkillpydicom
Python package for working with DICOM files. It allows you to read, modify, and write DICOM data in a Pythonic way. Essential for medical imaging processing, clinical data extraction, and AI in radiology.
Also in 5 projects that use this
tondevrelSkillsimpy
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 5 projects that use this
yf8578Skilldeeptools
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 4 projects that use this
yf8578Skilldnanexus-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 4 projects that use this
Hongyu-yuSkilltorch-geometric
Graph Neural Networks (PyG). Node/graph classification, link prediction, GCN, GAT, GraphSAGE, heterogeneous graphs, molecular property prediction, for geometric deep learning.
Also in 5 projects that use this
- +1 more from tondevrel
- +6 more from yf8578
Other versions10 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 10
- LeonChaoX/qinyan-academic-skills★ 932same name
- DAAF-Contribution-Community/daaf★ 236same name
- qinyan-ai/qinyan-academic-skills★ 80same name
- Barrios88/barrios-skills★ 30same name
- tondevrel/scientific-agent-skills★ 23same name
- JunMA98/Computer-science-claude-skills★ 3same name
- silvainfm/claude-skills★ 3same name
- BrightGold70/skills★ 1same name
- oornnery/agents★ 1same name
- yf8578/claude-skills-collection★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
We split this skill into the rules it gives an agent
9 rules. 0 are common, 1 is distinctive, and 8 are very specific to this project.
0
Common
Most of the 10 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 35
When no data processing library has been specified, use Polars.
- Very specific: line 40
Data already in memory is no exception: When a query starts from a DataFrame — a function argument, pl.from_pandas(pdf), pl.DataFrame(...), …
- Distinctive: line 61
When the user asks a question about data ("which region grew fastest last quarter?"), the goal is a correct answer in one shot: spend one …
- Very specific: line 84
Read references/insight-recipes.md first for ready-made query shapes (top-k, period-over-period, distributions, time series, cohort-style …
- Very specific: line 89
Expressions over Python functions: Never use map_elements, map_batches, map_groups (or the removed apply) when an expression exists — …
- Very specific: line 94
Filter early: Place filter() before group_by(), join(), and with_columns() so less data flows through every later step.
- Very specific: line 108
Polars is strictly typed: No implicit coercion, no mixed-type columns.
- Very specific: line 193
Always .alias() derived columns — or .name.suffix(...) for an expanded expression, which keeps every source name.
- Very specific: line 201
pandas names don't transfer: No index, no iloc, no groupby.
“Common” is measured: kept by at least 6 in 10 of the 10 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Polars
Default stance
When no data processing library has been specified, use Polars. Always use
the lazy API: build the whole query, then execute it with one .collect(),
so Polars can optimize the plan before any data is read. Eager execution
skips that optimization, so the same logic does more work.
Data already in memory is no exception. When a query starts from a
DataFrame — a function argument, pl.from_pandas(pdf),
pl.DataFrame(...), or an earlier collect() — call .lazy() before the
first operation and .collect() at the end. .lazy() is free (it wraps the
data, it does not copy it) and it is what turns a step-by-step eager pipeline
into one optimized plan. Do this unless the user asks for eager execution.
# start from a file
pl.scan_csv("data.csv").filter(...).collect()
# start from an existing DataFrame — wrap it first
df.lazy().filter(...).group_by(...).agg(...).collect()
# avoid: eager, step by step, nothing to optimize
df = pl.read_csv("data.csv")
df.filter(...).group_by(...).agg(...)From question to insight
When the user asks a question about data ("which region grew fastest last quarter?"), the goal is a correct answer in one shot: spend one cheap step on schema discovery, then write the full query once.
- Discover the schema first. Never guess column names or dtypes.
lf = pl.scan_csv("sales.csv") # or scan_parquet / scan_ndjson
print(lf.collect_schema()) # names and dtypes, no data read
print(lf.head(5).collect()) # eyeball values, formats, dirt- Translate the question into one lazy chain following the canonical pattern below. Map vague terms to explicit definitions and state them in the answer ("growth = revenue vs. previous quarter, percent").
- Handle dirt at the scan, not downstream:
pl.scan_csv(path, null_values=["N/A", ""], try_parse_dates=True). - Collect once, then sanity-check the result before answering — the
checks are at the end of
references/insight-recipes.md. - Answer with numbers, not just code. Lead with the insight, show the supporting table, and keep the LazyFrame around so follow-ups extend the chain instead of rebuilding it.
Read references/insight-recipes.md first for ready-made query shapes (top-k,
period-over-period, distributions, time series, cohort-style questions).
Core rules
- Expressions over Python functions. Never use
map_elements,map_batches,map_groups(or the removedapply) when an expression exists — almost always one does. Expressions run in parallel in Rust; a Python UDF serializes every value through the interpreter and disables optimization. - Filter early. Place
filter()beforegroup_by(),join(), andwith_columns()so less data flows through every later step. - One context, one expression per operation. Pass all expressions to a
single
with_columns(); expressions in one context run in parallel, and repeated calls in a loop serialize them. When the same operation applies to several columns, do not build one expression per column either — write one expression and let it expand over the schema:pl.col("a", "b"),pl.col(pl.Float64),pl.col("^sales_.*$"),cs.numeric(),pl.all().exclude("id"). Rename the expanded set with.name.suffix("_x")/.name.prefix()/.name.map(fn);.alias()names one output only. Selector catalogue and caveats:references/expressions.md. - Chain everything, collect once. An intermediate
.collect()materializes data and discards the plan, so everything after it optimizes from scratch. - Polars is strictly typed. No implicit coercion, no mixed-type
columns. Cast explicitly with
.cast(); use.cast(pl.Float64, strict=False)to turn unparseable values into nulls instead of errors. - Respect warnings — never silence them. A Polars warning names the
exact fix in its message:
PerformanceWarningand subclasses likePolarsInefficientMapWarningtell you to usecollect_schema(), or to rewrite amap_elementscall as a native expression. Apply the change; neverwarnings.filterwarnings("ignore")orwarnings.catch_warnings()to hide it.
import polars.selectors as cs
# avoid: same operation, one expression per column
lf.with_columns([(pl.col(c) * 1.1).alias(f"{c}_adj") for c in ["a", "b", "c"]])
# prefer: one expression, expanded by the schema
lf.with_columns((pl.col("a", "b", "c") * 1.1).name.suffix("_adj"))
lf.with_columns(cs.numeric().fill_null(0)) # in place, same namesCanonical query pattern
Build queries in this order. Each step reduces data before the next.
customers = pl.scan_csv("customers.csv")
result = (
pl.scan_csv("orders.csv") # 1. scan, never read
.filter(pl.col("year") == 2024) # 2. filter early
.join(customers, on="customer_id", how="left") # 3. join filtered data
.with_columns( # 4. add computed columns
(pl.col("revenue") - pl.col("cost")).alias("profit")
)
.group_by("region") # 5. group
.agg( # 6. aggregate
pl.col("profit").sum().alias("total_profit"),
pl.col("profit").mean().alias("avg_profit"),
pl.len().alias("count"),
)
.filter(pl.col("count") > 10) # 7. filter groups
.sort("total_profit", descending=True) # 8. sort
.select("region", "total_profit", "avg_profit") # 9. final columns
.collect() # 10. execute once
)Context selection
| Context | Use when | Output |
select() | Choosing or transforming columns | Only specified columns |
with_columns() | Adding or replacing columns | All columns plus new |
filter() | Removing rows | Same columns, fewer rows |
group_by() + agg() | Aggregating per group | One row per group |
over() | Group aggregate broadcast to all rows | Same shape as input |
sort() | Ordering rows | Same shape, reordered |
join() | Combining two frames | Columns from both |
The critical distinction: group_by().agg() returns one row per group;
over() keeps all rows and broadcasts the group result back — use it inside
with_columns() when every row needs its group's aggregate.
Gotchas
Each of these fails silently or with a confusing error.
- Strings in
then()/otherwise()are column names, not values.pl.when(c).then("adult")reads a column calledadult(or raisesColumnNotFoundError). Wrap literals:.then(pl.lit("adult")). - Null comparisons drop rows silently.
filter(pl.col("v") > 2)excludes nulls becausenull > 2is null, which is falsy. If nulls should be kept:(pl.col("v") > 2) | pl.col("v").is_null(). - Use
&,|,~with parentheses around each condition. Python'sand/or/notraise on expressions, and without parentheses operator precedence binds the comparison wrong:(pl.col("a") > 1) & (pl.col("b") < 5). - A bare aggregation in
with_columns()broadcasts the global value to every row.with_columns(pl.col("v").mean())fills the column with the overall mean — it does not error. Add.over("group")for the per-group value aligned to each row. - Duplicate output names raise
DuplicateError. A computed column keeps its source name;select(pl.col("p"), pl.col("p") * 1.1)fails. Always.alias()derived columns — or.name.suffix(...)for an expanded expression, which keeps every source name. - Regex column selection needs
^...$anchors.pl.col("sales_.*")is read as a literal column name and raisesColumnNotFoundError;pl.col("^sales_.*$")expands. Onecol()call cannot mix names with dtypes — use a selector instead. - Nulls don't match in joins by default. Rows with null keys silently
drop out of inner joins; pass
nulls_equal=Trueif they should match. - pandas names don't transfer. No index, no
iloc, nogroupby; verify any method you're not certain about (see below) rather than assuming the pandas spelling exists.
Version and API verification
The API moved at 1.0 (for example str.lengths() became str.len_chars(),
and pl.NUMERIC_DTYPES gave way to polars.selectors). Before writing a
method call you are not certain about, verify it against the installed
version rather than memory:
- MCP (preferred): install
polars-mcpin the project environment for live lookups —polars_search_api("filter")finds methods by keyword,polars_browse("Expr.str")explores a namespace, andpolars_get_docstring("Expr.str.contains")gets the exact signature. - Otherwise fetch the docs: the top of
references/expressions.mdmaps all 18 expression categories to their live URLs on https://docs.pola.rs.
When to load references
These reference files hold detail that is NOT in this file. When a task
matches one below, you MUST read that reference before writing code — do not
translate or answer from memory when a reference covers the task. Each file
opens with a ## Contents line for jumping to a section.
- Translating pandas → Polars — MUST read
references/pandas-to-polars.mdfirst (it's short). It carries API-difference traps absent from this file. - Answering a natural-language data question — read
references/insight-recipes.mdfor ready-made query shapes. references/contexts.md— detailed behavior ofselect,with_columns,filter,group_by/agg,over(window mapping strategies),sort, andjoin.references/expressions.md— string, temporal, list, struct, expansion and selector syntax; casting; null handling; conditionals; plus the fetch-map described above.references/lazy-api.md— scan options for dirty data, query plan inspection withexplain(), streaming engine for larger-than-memory data,sink_parquet.
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
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.

