A lightweight DataFrame and tabular-data library for MoonBit
Dependencies
// API shape (illustrative; see "Quick start" below for a runnable,
// `@moonframe`-prefixed version)
read_csv("sales.csv")
.filter(col("product").eq(lit_str("widget")))
.group_by([col("region")])
.agg([col("revenue").sum()])
.to_markdown()moon add ihb2032/MoonFrameimport {
"ihb2032/MoonFrame" @moonframe,
}MoonBit v0.10.4 deprecates the legacy JSON package manifest. New and migrated projects should use moon.mod / moon.pkg, as this repository does.
region,product,revenue,quantity
west,widget,100,10
east,gadget,50,5
west,gadget,70,7
east,widget,30,3
north,widget,40,4
north,gadget,60,6
west,gizmo,90,9
east,gizmo,20,2fn widgets(path : String) -> String raise @moonframe.DataError {
@moonframe.read_csv(path)
.filter(@moonframe.col("product").eq(@moonframe.lit_str("widget")))
.select(@moonframe.cols(["region", "revenue", "quantity"]))
.sort([
(
@moonframe.col("quantity"),
@moonframe.SortOrder::Desc,
@moonframe.NullOrder::NullsLast,
),
])
.to_markdown()
}| region | revenue | quantity |
| ------ | ------- | -------- |
| west | 100 | 10 |
| north | 40 | 4 |
| east | 30 | 3 |let summary = @moonframe.read_csv("sales.csv")
.group_by([@moonframe.col("region")])
.agg([
@moonframe.col("revenue").sum().with_alias("revenue"),
@moonframe.col("quantity").sum().with_alias("quantity"),
])| region | revenue | quantity |
| ------ | ------- | -------- |
| west | 260 | 26 |
| east | 100 | 10 |
| north | 100 | 10 |let result : Result[String, @moonframe.DataError] = Ok(widgets("sales.csv")) catch {
e => Err(e)
}moon run examples/sales_analysis # filter → select → sort → describe → markdown
moon run examples/data_cleaning # drop_nulls → fill_null → CSV round-trip
moon run examples/reporting # group_by → to_html + Vega-Lite spec
moon run examples/expressions # with_columns → filter → agg → lazy + explaintypes/ value types, errors (DataError), schemas
internal/column/ Arrow-style storage — validity bitmap + Builtin/Numeric backends; wrapped by Series and read by internal/kernel (which packages may name it is enforced by check_layering.sh)
internal/kernel/ the vectorized expression kernels — Series broadcasting, arithmetic / logic / comparison / string ops, ternary, map, and the dtype inference behind a computed column; called by frame's evaluator
internal/text/ shared text primitives — lexicographic compare, debug escaping, decimal literal parsing
internal/numeric/ shared numeric primitives — exact Int64/Double comparison and the extremum fold, used from types up through the kernels
internal/order/ shared position primitives — the stable index sort behind every sort, and the row-count clamp behind every head / tail / limit
internal/literal/ the one scalar-literal renderer, shared by expr / lazy plan rendering
internal/ir/ module-internal expression AST — ExprNode + the operator tags, walked by the engine
series/ Series + column-level stats + the shared reduction / rebuild / key-cell kernels
expr/ opaque Expr handle — constructors, operators, when/then/otherwise builders, to_string rendering
frame/ DataFrame + the operators (usually one per file) + group_by + join + the expression evaluator (with_columns / select / filter / agg) + to_markdown / to_html
io/ CSV (NyaCSV-backed), JSON, NDJSON read / write + Vega-Lite export
lazy/ deferred query plan — LazyFrame builders, collect / explain, predicate + projection pushdown
moonframe.mbt the root package — facade over the public API (fluent-chain intermediates stay in their sub-packages)internal/column how a column is laid out: data buffers + validity bitmap
series what a column is: dtype, validity, backend convergence
internal/kernel how a column is computed: one vectorized pass per operator
frame and above what a verb means: row sets, scheduling, schema, errorsmoon check # type-check the workspace
moon test # run all tests (add --target all for every backend)
moon fmt # format sources
moon info # regenerate .mbti interface snapshotsA lightweight DataFrame and tabular-data library for MoonBit
Dependencies