Tables
A model holds rows of data in tables. Every table is a subclass of
Table and exposes a fluent builder API for adding
fields and validators.
The four concrete table types each address a different shape of data:
DataTable — raw data and decision variables
DerivedTable — grouped, sorted, filtered view of a source table
JoinedTable — rows produced by joining two or more tables
UnionTable — rows stacked from multiple source tables
- class Table(id)[source]
Bases:
Buildable,_TableBaseThe base class for all table types.
This class defines the core structure and behavior of a table, including field management and relationships with derived tables.
- property key_column: str | None
The key column field ID used for object references, or
Noneif not set.
- property validation_group: str | None
The validation group identifier, or
Noneif not assigned to a group.
- property display_name: str
The human-readable display name for this table. Defaults to the table ID.
- set_model_level(model_level)[source]
Sets whether this table is model-level. Returns self.
- Return type:
- set_validation_group(group)[source]
Sets the validation group for this table. Returns self.
- Return type:
- set_export_as_key_column(export_as_key=True)[source]
- Configures the table to export its key column instead of the row number when generating
reports. Returns self.
- initialise_field(id, data_type)[source]
Registers a placeholder field with the given ID and data type.
Use this when a field must exist before its final definition is known — for example, when using PREV or NEXT, or to resolve circular dependencies in combo fields. The placeholder will be automatically replaced when add_calculated_field or add_combo_field is later called with the same id.
- add_data_field(id, data_type, tracking_group=None)[source]
Adds a data field to the table.
This method should be implemented by subclasses and is not valid for the base Table class.
- Raises:
NotImplementedError – Always raised since this method is not applicable to Table.
- Return type:
- add_object_reference_field(id, table, is_array=False, tracking_group=None)[source]
Adds an object reference field to the table.
- add_calculated_field(id, formula, order_index=None, description=None, tracking_group=None)[source]
Adds a CalculatedField to the table.
- get_field(id)[source]
Retrieves a field from the table.
- Parameters:
id (
str) – The ID of the field to retrieve.- Returns:
The field object matching the given ID.
- Return type:
- Raises:
ValueError – If the field does not exist in the table.
- get_validation_state()[source]
Build a calculated field representing the maximum severity rank among all currently-invalid fields in this table.
For each field with validators,
COUNT(table[field__invalid__severity], True) > 0is used to check whether any row is invalid at that severity level. The result is a scalar formula — all rows will carry the same value — evaluating to the highestSEVERITY_RANKamong failing fields, or0when nothing is invalid.The result is registered in the table as a calculated field named
__validation_state__. Subsequent calls return the already-registered field without rebuilding it.- Returns:
A calculated field whose value is the highest severity rank of any currently-invalid field in this table.
- Return type: