polars-2-lazy-evaluation-and-query-optimization
Sub-skill of polars: 2. Lazy Evaluation and Query Optimization.
Best use case
polars-2-lazy-evaluation-and-query-optimization is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Sub-skill of polars: 2. Lazy Evaluation and Query Optimization.
Teams using polars-2-lazy-evaluation-and-query-optimization should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/2-lazy-evaluation-and-query-optimization/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How polars-2-lazy-evaluation-and-query-optimization Compares
| Feature / Agent | polars-2-lazy-evaluation-and-query-optimization | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Sub-skill of polars: 2. Lazy Evaluation and Query Optimization.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 2. Lazy Evaluation and Query Optimization
## 2. Lazy Evaluation and Query Optimization
**LazyFrame Basics:**
```python
import polars as pl
# Create lazy frame (no computation yet)
lf = pl.scan_csv("large_data.csv")
# Or convert from eager DataFrame
df = pl.DataFrame({"x": [1, 2, 3]})
lf = df.lazy()
# Chain operations (still no computation)
result_lf = (
lf
.filter(pl.col("date") >= "2025-01-01")
.with_columns([
(pl.col("revenue") - pl.col("cost")).alias("profit"),
pl.col("category").cast(pl.Categorical)
])
.group_by("category")
.agg([
pl.col("profit").sum().alias("total_profit"),
pl.col("profit").mean().alias("avg_profit"),
pl.count().alias("count")
])
.sort("total_profit", descending=True)
)
# View the query plan
print(result_lf.explain())
# Execute and collect results
result_df = result_lf.collect()
# Execute with streaming (for very large data)
result_df = result_lf.collect(streaming=True)
# Fetch only first N rows
sample = result_lf.fetch(1000)
```
**Query Optimization Benefits:**
```python
# Polars optimizes this automatically:
lf = (
pl.scan_parquet("data/*.parquet")
.filter(pl.col("country") == "USA") # Predicate pushdown
.select(["id", "name", "revenue"]) # Projection pushdown
.filter(pl.col("revenue") > 1000) # Combined with first filter
)
# View optimized plan
print("Naive plan:")
print(lf.explain(optimized=False))
print("\nOptimized plan:")
print(lf.explain(optimized=True))
# The optimizer will:
# 1. Push filters to data source (read less data)
# 2. Select only needed columns (reduce memory)
# 3. Combine/reorder operations for efficiency
# 4. Eliminate redundant operations
```
**Streaming Large Files:**
```python
# Process files larger than memory
def process_large_file(input_path: str, output_path: str):
"""Process file that doesn't fit in memory."""
result = (
pl.scan_csv(input_path)
.filter(pl.col("status") == "active")
.group_by("region")
.agg([
pl.col("sales").sum(),
pl.col("customers").n_unique()
])
.collect(streaming=True) # Stream processing
)
result.write_parquet(output_path)
return result
# Sink directly to file (even more memory efficient)
(
pl.scan_csv("huge_file.csv")
.filter(pl.col("value") > 0)
.sink_parquet("filtered_output.parquet")
)
```Related Skills
library-evaluation-integration
Create evaluation scripts and integration tests for Python scientific libraries in the digitalmodel package. Follows the established pattern from fluids, ht, meshio, sectionproperties, and pygmt evaluations.
skill-chain-context-optimization
Refactor large or frequently-run skills into context-efficient chains using isolated execution, file-backed handoffs, minimal summaries, and runtime-aware command substitution.
usage-optimization
Optimize AI usage efficiency through script-first patterns, batch operations, and input preparation
docker-1-image-optimization
Sub-skill of docker: 1. Image Optimization (+4).
oil-and-gas-economic-evaluation
Sub-skill of oil-and-gas: Economic Evaluation (+2).
orcaflex-mooring-iteration-1-scipy-optimization-recommended
Sub-skill of orcaflex-mooring-iteration: 1. Scipy Optimization (Recommended) (+2).
drilling-drilling-optimization
Sub-skill of drilling: Drilling Optimization (+2).
mcp-builder-example-1-database-query-tool
Sub-skill of mcp-builder: Example 1: Database Query Tool (+1).
sql-queries-bigquery-google-cloud
Sub-skill of sql-queries: BigQuery (Google Cloud) (+2).
polars-polars-with-plotly-visualization
Sub-skill of polars: Polars with Plotly Visualization (+1).
polars-6-joins-and-concatenation
Sub-skill of polars: 6. Joins and Concatenation.
polars-4-groupby-and-aggregations
Sub-skill of polars: 4. GroupBy and Aggregations (+1).