Module Talon
Tables: named, typed columns.
Types say what columns store and Kinds what their cells read as in OCaml. Binary, Time and Record are the OCaml values that cells read as, Schemas name and type a table's columns, and Tz reads the time zone database.
A Query is the centre: a plan over a table or a Source, transformed by verbs, whose schema is known before any data is read. Its verbs take Expressions, read through Col handles and Ext declarations; Sel chooses columns, Order sorts, and Join conditions pair rows. Plan problems raise Invalid_argument; failures in data are Error values.
type tThe type for tables: named, typed columns of equal length.
Tables
v ?rows cs is the table of the columns cs, in order, as one batch of rows rows. rows defaults to the length of the columns, and gives the rows of a table without columns, such as the batch a source yields for a request that reads none.
Raises Invalid_argument if cs is empty and rows is not given, if rows is negative or is not the columns' length, if two columns have the same name, if a name is not valid UTF-8, or if the columns have different lengths.
of_batches ts is the rows of ts one after the other, without a copy, in O(number of batches). Each table's batches become the result's.
Raises Invalid_argument if ts is empty or the tables' schemas differ (Schema.equal).
batches t is t's batches, each a table of one batch, in order. A table without rows has none.
column t name is the column name of t, canonical (Column): t's own when it already is.
Raises Invalid_argument if t has no column name.
val take : Nx.host Nx.int64_t -> t -> ttake indices t is the rows of t at indices, in order, as one batch: take (Nx.Rng.permutation ~key (rows t)) t shuffles every column.
Raises Invalid_argument if indices is not 1-D or holds an index outside [0;rows t - 1]; under Rune.jit, for traced indices (Compiled, mapped and differentiated runs), the index outside raises when the call returns.
to_tensor dt names t is the (rows t, List.length names) matrix whose column j is the column List.nth names j of t, each value converted to dt as Nx.cast converts it. It is the one copy a columnar layout forces. The columns are numeric or boolean, and have no null.
Raises Invalid_argument if a name is not a column of t, if a column is neither numeric nor boolean, or has a null; under Rune.jit, for a traced validity (Compiled, mapped and differentiated runs), the null raises when the call returns.
val to_dense :
('a, 'b) Nx.dtype ->
axes:(string * int) list ->
string ->
t ->
('a, 'b, Nx.host) Nx.t * Nx.host Nx.bit_t optionto_dense dt ~axes value t is t's column value scattered into a tensor, and its validity. axes lists each axis as its key column and extent, outermost first, and cells lie in row-major order. A key is a categorical code, whose dictionary has the extent's size, or an integer in [0;extent - 1]. A cell no row names holds zero, and so does a null value; the validity clears each such cell and is None when every cell holds a value. The value column is numeric or boolean, converted as Nx.cast converts it.
Raises Invalid_argument if axes is empty or names a column twice, if an extent is negative or a categorical's differs from its dictionary's size, if a key column is neither categorical nor an integer or holds a null or a key outside its extent, if two rows name one cell, if value is neither numeric nor boolean, or if the cells exceed OCaml's int.
val of_dense :
?validity:Nx.host Nx.bit_t ->
axes:string list ->
string ->
('a, 'b, Nx.host) Nx.t ->
tof_dense ~validity ~axes value x is the table of one row per element of x, in row-major order: an int64 key column per name of axes, then the elements in column value, null where validity is clear. The column shares x's memory where Nx.flatten returns a view. to_dense with the same axes and extents returns x, with zeros where validity is clear.
Raises Invalid_argument if axes is empty or has not x's dimensions, if validity's shape is not x's, or as v does.
equal t0 t1 is true iff t0 and t1 have equal schemas and the same keys row by row, by key identity (Type.compare_value, null being one more key), whatever their batches.
Raises Invalid_argument over traced columns (Compiled, mapped and differentiated runs).
Display
type limits = {- #
head : int;(*The rows shown from the start.
*) - #
tail : int;(*The rows shown from the end.
*) - #
columns : int;(*The columns shown, from the first.
*) - #
width : int;(*The widest cell, in Unicode scalar values.
*)
}The type for display limits. A table of at most head + tail rows shows all of them.
pp_with l ppf t formats t for people, reading only the rows it shows. With { limits with head = 2; tail = 1 }:
table 16 rows × 4 columns carrier mean_delay flights name string float64 int64 string OO 58.0000 9 ∅ F9 53.4214 280 Frontier Airlines Inc. ⋮ HA 29.0000 1 Hawaiian Airlines Inc. 13 rows not shown
- a header, then the names and types of the shown columns;
- all rows, or the first
l.head, a⋮line, the lastl.tail, and the number of rows not shown; - with more than
l.columnscolumns, a last line naming those not shown.
A null is ∅. Text shows as it reads, its control characters and bytes that are not UTF-8 escaped as Type.pp_quoted escapes them, cut with … past l.width scalar values. Numbers are right-aligned; the floats of a column show with one number of decimals, the fewest, up to six, that give each shown value six significant digits, or in scientific notation when a shown value needs it. Other values show in the text that Column.parse reads, such as 2024-03-15T09:30:00.5Z for an instant; durations and clocks as Time.Span.pp formats them, lists as OCaml lists, and records and tensors as <record> and <tensor>.
Raises Invalid_argument if a limit is negative or l.width is 0, and over traced columns or under Rune.grad (Compiled, mapped and differentiated runs).
Decimals in files
A decimal of a file, the number unscaled × 10{^-scale} of at most a precision's digits, has no talon type. A file format leaves its column undeclared until the reader declares it with the format's with_type, as float64, the float nearest each value, or, up to 18 digits, as int64, each value's unscaled integer, a value outside int64 failing when it is read. An int64 means what its scale says, so a format that declares one reads only a file whose column has that scale, and any other fails when read. A list or record that holds a decimal is undeclared as a whole. A source of a format that leaves a column undeclared refuses to be read, naming the column and the types it reads as.