Skip to content

Polars DataFrames

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.

Terminal window
cargo install nu_plugin_polars
plugin add ~/.cargo/bin/nu_plugin_polars

Restart Nushell or run plugin use polars. Verify:

Terminal window
stars version
# polars field should show "available" instead of "not installed"
Terminal window
stars --dataframe

Returns a Polars DataFrame that you can chain with Polars commands:

Terminal window
# Filter Rust repos with 1000+ stars
stars --dataframe
| polars filter ((polars col language) == "Rust")
| polars filter ((polars col stargazers_count) > 1000)
| polars sort-by stargazers_count --reverse
| polars collect
Terminal window
stars --lazyframe

Returns a LazyFrame — operations are not executed until you call polars collect. This is more efficient for complex multi-step transformations:

Terminal window
stars --lazyframe
| polars filter ((polars col language) == "TypeScript")
| polars group-by language
| polars agg [(polars col stargazers_count | polars mean)]
| polars collect
Terminal window
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 20
Terminal window
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 collect

Use polars into-nu to convert a DataFrame back to a standard Nushell table for further processing with non-Polars commands:

Terminal window
stars --dataframe
| polars filter ((polars col language) == "Rust")
| polars collect
| polars into-nu
| each { |row| $"($row.full_name): ($row.stargazers_count) stars" }

When converting to Polars, the module maps columns to these Polars dtypes:

ColumnPolars Type
idi64
owner, name, full_name, description, urlstr
language, homepage, license, topicsstr
stargazers_count, forks_count, open_issues_count, sizei64
pushed_at, created_at, updated_at, synced_at, starred_atdatetime[us]
archived, forkbool