Reshape
Coral.Reshape provides wide-to-long and long-to-wide transformations on
Frame values. All four operations are compile-checked against
chelis v0.7.6.
Validated operations in the current slice:
melt: wide to long, repeat id columns, pivot value columns intovariable/valuerowspivot: long to wide, unique values ofcolumns_colbecome new column namesstack: thin shim,meltwith no id columns, all columns as value columnsunstack: thin shim,pivoton a stacked frame given an explicit index column
v0.1 constraints:
values_colforpivotmust beFloatCol; other types fail with a runtime error.value_colsformeltmust all beFloatCol.index_colandcolumns_colforpivotmust beStringCol.id_colsformeltmust beStringCol.
module Coral.BookReshapeimport Coral.Frame (from_pairs, nrows, ncols)import Coral.Reshape (melt)export (main)def main() -> int64 = { frame = from_pairs([("city", StringCol(["london", "paris", "oslo"])), ("qty", FloatCol(to_tensor([cast(5.0, f32), cast(6.0, f32), cast(7.0, f32)]))), ("price", FloatCol(to_tensor([cast(10.0, f32), cast(20.0, f32), cast(30.0, f32)])))]) melted = melt(frame, ["city"], ["qty", "price"]) nrows(melted)}The output frame has columns variable, value, and city with
nrows = 3 * 2 = 6 (one row per original row per value column).
The gate today is fixture-backed plus compile-checked. A full executed runtime parity lane for Reshape will follow when the bare-build harness is extended to cover multi-column frames.