Labeled data¶
Alignment of labeled arrays and tables to the canonical layout of a tensor type, by axis name and coordinate. The surface is in Programs and data.
axis_data
¶
Binding labeled data to tensors indexed by finite types.
A value for a tensor type with named axes is matched to the axes by label, never by position. It may be given as
- a labeled array: an xarray
DataArray, or its dictionary form{"dims": [...], "coords": {...}, "data": [...]}(whatDataArray.to_dict()writes, and whatqvr run --datareads as JSON), whose dimension names are the tensor's axis names and whose coordinates along a named axis are that axis's coordinate labels; - a columnar table: a data frame (any object with
columnswhose columns convert withto_numpy()), or{"columns": {name: [...], ...}}, with one column per axis holding each row's coordinate and one more column holding the value. A record axis may instead be given by one column per field.
An axis's name is its type's rendering (World, Bool,
{knows : Bool, linguist : Bool}) or Fin n for a positional axis; a
name repeated within one tensor type is suffixed #1, #2
(tensor_axes). A coordinate is an element's
label: true, Linguist, {knows = true, linguist = false}, or a
position for Fin n.
Alignment checks the dimension names and the coordinate set of every axis and refuses a missing, an unknown, or a repeated coordinate with the coordinate named; it reorders labeled data into the canonical order the type fixes, and never reorders positional data. The aligned value is the nested tuple of the entries in canonical order, so two inputs that state the same entries (in any row order, as an array or a table) align to equal values and equal data digests. Positional data (nested lists or a tensor) is accepted for a tensor whose axes are all positional.
AxisDataError
¶
Bases: ValueError
Data whose labels do not match the axes of its tensor type.
The message names the axis and the coordinate that do not match.
LabeledArray
¶
Bases: Protocol
An array with named dimensions and coordinate labels, as xarray's.
ColumnarTable
¶
Bases: Protocol
A table of named columns, as a pandas or polars data frame.
__getitem__
¶
Read one column by name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The column's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
The column in the table's native representation. |
Source code in src/quivers/qiec/axis_data.py
ModuleDeclarations
¶
ModuleDeclarations(module: QiecModule)
The family and constructor declarations of a checked module.
| PARAMETER | DESCRIPTION |
|---|---|
module
|
The module.
TYPE:
|
Source code in src/quivers/qiec/axis_data.py
families
property
¶
families: Mapping[FamilyId, FamilyDecl]
The module's families, by identity.
| RETURNS | DESCRIPTION |
|---|---|
Mapping[FamilyId, FamilyDecl]
|
The families. |
constructors
property
¶
constructors: Mapping[ConstructorId, ConstructorDecl]
The module's constructors, by identity.
| RETURNS | DESCRIPTION |
|---|---|
Mapping[ConstructorId, ConstructorDecl]
|
The constructors. |
coordinate_label
¶
coordinate_label(item: Scalar) -> str
The label a data coordinate denotes.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
A coordinate as data holds it.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
| RAISES | DESCRIPTION |
|---|---|
AxisDataError
|
If the coordinate is a non-integral number. |
Source code in src/quivers/qiec/axis_data.py
labeled
¶
Whether a value carries axis labels.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A datum.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True for a labeled array or table, or their dictionary forms. |
Source code in src/quivers/qiec/axis_data.py
align_value
¶
align_value(value: object, type_: TypeExpr, declarations: Declarations, *, name: str) -> object
Align one datum to the canonical layout of its tensor type.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The datum: labeled (an array, a table, or their dictionary forms), or positional.
TYPE:
|
type_
|
The parameter's type.
TYPE:
|
declarations
|
The declarations its axis types refer to.
TYPE:
|
name
|
The parameter's name, for the diagnostics.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
The entries in canonical order as nested tuples, for labeled data; the datum itself for positional data of a tensor with positional axes only, or of a type that is not a tensor. |
| RAISES | DESCRIPTION |
|---|---|
AxisDataError
|
If labeled data does not match the axes, or positional data is given for a tensor with a named axis. |
Source code in src/quivers/qiec/axis_data.py
align_axes
¶
align_axes(value: object, axes: tuple[TensorAxis, ...], *, name: str, dimensions: tuple[IndexTerm, ...] | None = None) -> Entries
Align labeled data to axes given by name and coordinates.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
A labeled array or table, or their dictionary forms.
TYPE:
|
axes
|
The axes in layout order, each with its name and coordinates.
TYPE:
|
name
|
The datum's name, for the diagnostics.
TYPE:
|
dimensions
|
The axes' dimensions, which let a record axis be read from one column per field; None when the axes are not named by types.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Entries
|
The entries in the axes' order, nested as tuples. |
| RAISES | DESCRIPTION |
|---|---|
AxisDataError
|
If the data's dimensions are not the axes, or an axis's coordinates do not match. |
Source code in src/quivers/qiec/axis_data.py
axis_coordinates
¶
axis_coordinates(type_: TypeExpr, declarations: Declarations) -> tuple[TensorAxis, ...]
The axes a datum of a tensor type is labeled with.
| PARAMETER | DESCRIPTION |
|---|---|
type_
|
A tensor type.
TYPE:
|
declarations
|
The declarations its axis types refer to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[TensorAxis, ...]
|
Its axes in canonical order, with names and coordinates; empty for a type that is not a tensor. |