Polars DataFrames
Overview
Section titled “Overview”The stars command supports two Polars output modes via optional flags:
--dataframe— returns a Polars DataFrame (eager evaluation)--lazyframe— returns a Polars LazyFrame (lazy evaluation, optimized query plan)
These require the nu_plugin_polars Nushell plugin.
Installing Polars
Section titled “Installing Polars”cargo install nu_plugin_polarsplugin add ~/.cargo/bin/nu_plugin_polarsRestart Nushell or run plugin use polars. Verify:
stars version# polars field should show "available" instead of "not installed"DataFrame output
Section titled “DataFrame output”stars --dataframeReturns a Polars DataFrame that you can chain with Polars commands:
# Filter Rust repos with 1000+ starsstars --dataframe| polars filter ((polars col language) == "Rust")| polars filter ((polars col stargazers_count) > 1000)| polars sort-by stargazers_count --reverse| polars collectLazyFrame output
Section titled “LazyFrame output”stars --lazyframeReturns a LazyFrame — operations are not executed until you call polars collect. This is more efficient for complex multi-step transformations:
stars --lazyframe| polars filter ((polars col language) == "TypeScript")| polars group-by language| polars agg [(polars col stargazers_count | polars mean)]| polars collectExample analytics
Section titled “Example analytics”Language distribution
Section titled “Language distribution”stars --dataframe| polars group-by language| polars agg [ (polars col name | polars count | polars as count) (polars col stargazers_count | polars sum | polars as total_stars)]| polars sort-by count --reverse| polars collect| first 20Stars over time
Section titled “Stars over time”stars --dataframe| polars with-column [(polars col starred_at | polars str-slice 0 7 | polars as month)]| polars group-by month| polars agg [(polars col name | polars count | polars as starred)]| polars sort-by month| polars collectConverting back to Nushell tables
Section titled “Converting back to Nushell tables”Use polars into-nu to convert a DataFrame back to a standard Nushell table for further processing with non-Polars commands:
stars --dataframe| polars filter ((polars col language) == "Rust")| polars collect| polars into-nu| each { |row| $"($row.full_name): ($row.stargazers_count) stars" }Schema types
Section titled “Schema types”When converting to Polars, the module maps columns to these Polars dtypes:
| Column | Polars Type |
|---|---|
id | i64 |
owner, name, full_name, description, url | str |
language, homepage, license, topics | str |
stargazers_count, forks_count, open_issues_count, size | i64 |
pushed_at, created_at, updated_at, synced_at, starred_at | datetime[us] |
archived, fork | bool |