github ↗
docs menu

talon

data and visualization · like pandas / Polars

Talon is a library of tables: named, typed columns of equal length. A missing value is null, a state of its own that no number stands for, and rows have no labels. Columns are laid out over nx buffers, so a numeric column becomes an nx tensor without a copy.

install
opam install talon
built on
nx

Quick start

Read flights from a CSV file and carriers from a Parquet file, average the late departures per carrier, and name each carrier:

ocaml
open Talon

let ( let* ) = Result.bind
let delay = Col.int "dep_delay"

let late_by_carrier () =
  let* flights = Talon_csv.file ~nulls:[ "NA" ] "flights.csv" in
  let* carriers = Talon_parquet.file "carriers.parquet" in
  Query.(
    of_source flights
    |> filter Expr.(delay > int 15)
    |> aggregate ~by:[ "carrier" ]
         Expr.[ "mean_delay" := mean delay; "flights" := rows ]
    |> join ~on:(Join.keys [ "carrier" ]) ~each_left:One
         (of_source carriers)
    |> sort [ Order.desc "mean_delay" ]
    |> run)
table 7 rows × 4 columns
 carrier  mean_delay  flights  name
 string   float64     int64    string
 DL          38.0000        5  Delta Air Lines Inc.
 HA          36.6667        3  Hawaiian Airlines Inc.
 B6          31.0000        1  JetBlue Airways
 OO          29.0000        3  ∅
 F9          27.0000        2  Frontier Airlines Inc.
 AA          27.0000        1  American Airlines Inc.
 WN          26.0000        1  Southwest Airlines Co.

∅ is null: the carriers file has no name for OO.

How Talon works

  • A table is data. Talon.t holds columns, each a typed array with a bitmap of the rows that are null.
  • A query is a description. Query.t is a table or a file transformed by verbs: select, derive, filter, sort, slice, aggregate, join and append. Building one reads nothing, and Query.run computes it.
  • Expressions are typed. Col.int "dep_delay" names a column and reads it as int. An expression's type also says whether it has one value per row or one per group, so a column where a reduction belongs does not compile.
  • Plans fail before data. Each verb checks its expressions against its input's columns when it is applied and reports every problem at once.
  • Failures in data are values. A malformed file or a value that breaks a query's contract is an Error, which names the file, line, plan step or row.

Libraries

Library Module Contents
talon Talon Tables, columns, types, expressions and queries
talon.csv Talon_csv CSV files: sniffing, reading and writing
talon.json Talon_json JSON and NDJSON files: sniffing, reading and writing
talon.parquet Talon_parquet Parquet files, read mapped in memory and written from queries

Next steps

Worked problems from four domains:

Examples

  • 01-tables ↗Build a table from OCaml arrays, read a column back, and run a first query.
  • 02-flights ↗The pipeline of the guide: read flights from a CSV file and carriers from a Parquet file, keep the late departures, average them per carrier, join each carrier's name and sort.
  • 03-expressions ↗Expressions over a table of training losses: values per row, reductions per group, and reductions put back on the rows with over.
  • 04-joins ↗Join trials with subjects on subject = id with each kind of join, assert that every trial has exactly one subject, then join trial windows with the events inside them.
  • 05-formats ↗Read CSV text with a sniffed format, change a column's type, write the table back, and read a Parquet file whose row groups the filter can skip.
  • 06-mistakes ↗The two ways a query fails.
  • 07-features ↗Turn flights into a feature matrix and labels for a model.
  • 08-text-and-time ↗Text and temporal expressions over a table of recording sessions.
  • 09-many-columns ↗Work on many columns at once with selectors, and use the compositions of Kit.
  • 10-custom-source ↗Write a source of your own and fold a query over its batches.
  • 11-nested-columns ↗Columns of lists, tensors, records and an extension type.

this page is tested with mdxedit this page ↗