examples/

directory
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2026 License: MIT

README

golars examples

Runnable programs that demonstrate golars usage. Each subdirectory is a main package: run with go run ./examples/<name>.

A subset of examples ship a second main under generic/. That variant uses the typed expr.C[T] / expr.Int / expr.Float / expr.Str / expr.Bool facade introduced in expr/typed.go to eliminate expr.Lit(int64(X)) boilerplate. The logical plan is identical; only the caller syntax differs. Run with go run ./examples/<name>/generic.

Core API

Directory What it shows
basic Build a DataFrame from slices; basic operations (head, filter, sort).
describe Summary statistics via DataFrame.Describe(ctx).
expressions Column expressions (Col, literal, arithmetic) and select/with_columns.
groupby GroupBy with sum/mean/count aggregations.
join Inner and left joins across two DataFrames.
lazy The LazyFrame pipeline (filter → groupby → sort) with collect.
streaming Streaming execution over large inputs via the morsel engine.

Reshape / aggregation

Directory What it shows
horizontal SumHorizontal, MeanHorizontal, SumAll - row-wise + frame-scalar aggregates.
pivot df.Pivot(index, on, values, PivotSum) - long-to-wide reshape.
transpose_unpivot df.Transpose, df.Unpivot (melt).
topk_pipe df.TopK / df.BottomK, df.Pipe method-chaining helper.
over_window Expr.Over(keys...) - window functions broadcast back to rows.
rolling Expr.RollingMean/Std/Min/Max(window, minPeriods) on a price series.

Control flow / expressions

Directory What it shows
when_then When(pred).Then(a).Otherwise(b) with dtype promotion.
coalesce_concat Coalesce, ConcatStr, IntRange - polars-style constructors.
fill_strategies ForwardFill, BackwardFill, FillNan on a nullable time series.
stats Skew, Kurtosis, PearsonCorr, Covariance, ApproxNUnique, df.Corr.
regex_strings Str().Extract, ContainsRegex, SplitExactNullShort.

I/O

Directory What it shows
csv Read and write CSV files.
csv_url Fetch a CSV from an http(s) URL.
parquet Read and write Parquet files.
json Array-of-objects JSON read/write.
ndjson Newline-delimited JSON read/write.
arrow_interop DataFrame ↔ arrow.RecordBatch / arrow.Table round trip.
ipc_streaming Arrow IPC stream: write multiple batches, read them back.
scan_pushdown iocsv.Scan() with predicate + projection pushdown through to the reader.

Querying + tooling

Directory What it shows
sql Nested module. Read a query result into a DataFrame via modernc.org/sqlite (pure-Go). Run with cd examples/sql && go run ..
sql_session sql.Session Register + Query to run SQL directly against in-memory DataFrames.
script .glr script samples (agg, branching, derived, join, multisource, nulls, pipeline, regex, rolling) plus a host program driving script.Runner. script/transpiled/ has the same scripts lowered to Go via golars transpile.
profiler lazy.NewProfiler() + lazy.WithProfiler(p) for per-node timings.

Notes

Most examples create in-memory DataFrames so no external files are needed. The csv_url example hits httpbin.org; set GOLARS_EXAMPLE_URL to point at a different endpoint if that host is unreachable. scan_pushdown seeds a tiny CSV in $TMPDIR.

Directories

Path Synopsis
Arrow interop: DataFrame ↔ arrow.RecordBatch / arrow.Table.
Arrow interop: DataFrame ↔ arrow.RecordBatch / arrow.Table.
Build a DataFrame from slices, then take the head, filter, and sort.
Build a DataFrame from slices, then take the head, filter, and sort.
Coalesce + ConcatStr + IntRange - polars-style constructors.
Coalesce + ConcatStr + IntRange - polars-style constructors.
generic command
Typed-column variant of ./examples/coalesce_concat.
Typed-column variant of ./examples/coalesce_concat.
Write a DataFrame to CSV and read it back.
Write a DataFrame to CSV and read it back.
Fetch a CSV from an http(s) URL.
Fetch a CSV from an http(s) URL.
DataFrame.Describe: summary statistics for every column.
DataFrame.Describe: summary statistics for every column.
Column expressions used in select/with_columns.
Column expressions used in select/with_columns.
generic command
Typed-column variant of ./examples/expressions.
Typed-column variant of ./examples/expressions.
FillNull, ForwardFill, BackwardFill, FillNan.
FillNull, ForwardFill, BackwardFill, FillNan.
Group by a key column and run per-group aggregations.
Group by a key column and run per-group aggregations.
generic command
Typed-column variant of ./examples/groupby.
Typed-column variant of ./examples/groupby.
Row-wise aggregates: SumHorizontal, MeanHorizontal, MinHorizontal.
Row-wise aggregates: SumHorizontal, MeanHorizontal, MinHorizontal.
Write + read an Arrow IPC stream (cross-language binary format).
Write + read an Arrow IPC stream (cross-language binary format).
Inner and left joins across two DataFrames.
Inner and left joins across two DataFrames.
Parse JSON (array of objects) into a DataFrame and write it back.
Parse JSON (array of objects) into a DataFrame and write it back.
Build and collect a lazy pipeline: filter -> groupby -> sort.
Build and collect a lazy pipeline: filter -> groupby -> sort.
generic command
Typed-column variant of ./examples/lazy.
Typed-column variant of ./examples/lazy.
Parse newline-delimited JSON (one object per line) into a DataFrame.
Parse newline-delimited JSON (one object per line) into a DataFrame.
Window functions via Expr.Over(keys...).
Window functions via Expr.Over(keys...).
generic command
Typed-column variant of ./examples/over_window.
Typed-column variant of ./examples/over_window.
Write a DataFrame to Parquet and read it back.
Write a DataFrame to Parquet and read it back.
Pivot: long → wide reshape.
Pivot: long → wide reshape.
Attach a profiler to a lazy plan and print per-node timings.
Attach a profiler to a lazy plan and print per-node timings.
generic command
Typed-column variant of ./examples/profiler.
Typed-column variant of ./examples/profiler.
Regex + string ops: Extract, ContainsRegex, SplitN. Run: go run ./examples/regex_strings
Regex + string ops: Extract, ContainsRegex, SplitN. Run: go run ./examples/regex_strings
Rolling sum / mean / std on a single-column time series.
Rolling sum / mean / std on a single-column time series.
generic command
Typed-column variant of ./examples/rolling.
Typed-column variant of ./examples/rolling.
Lazy scan with predicate + projection pushdown.
Lazy scan with predicate + projection pushdown.
generic command
Typed-column variant of ./examples/scan_pushdown.
Typed-column variant of ./examples/scan_pushdown.
Shows how to drive a golars pipeline from a script file via the public script package.
Shows how to drive a golars pipeline from a script file via the public script package.
transpiled/agg command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/branching command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/demo command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/derived command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/join command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/multisource command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/nulls command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/pipeline command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/regex command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
transpiled/rolling command
Code generated by `golars transpile`.
Code generated by `golars transpile`.
Register in-memory DataFrames and run SQL against them.
Register in-memory DataFrames and run SQL against them.
Stats: skew, kurtosis, corr, cov, approx_n_unique.
Stats: skew, kurtosis, corr, cov, approx_n_unique.
Run a pipeline through the streaming/morsel engine.
Run a pipeline through the streaming/morsel engine.
generic command
Typed-column variant of ./examples/streaming.
Typed-column variant of ./examples/streaming.
TopK / BottomK / Pipe - nicer alternatives to Sort+Head.
TopK / BottomK / Pipe - nicer alternatives to Sort+Head.
Transpose and Unpivot (melt).
Transpose and Unpivot (melt).
Conditional expressions with when().then().otherwise().
Conditional expressions with when().then().otherwise().
generic command
Typed-column variant of ./examples/when_then.
Typed-column variant of ./examples/when_then.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL