RelatedTables#
- class sdm.relational.RelatedTables(tables: Mapping[str, T], relationships: Collection[Relationship | Mapping[str, str | Sequence[str]]], task_links: Collection[TaskLink | Mapping[str, str | Sequence[str]]])#
Bases:
DeviceMixin,Generic[T]Task-specific related tables attached to model inputs.
RelatedTablesstore the relational context provided to a model for a particular task table. It may contain a sampled subset of a largerRelationalData. Thetask_linksdescribe how rows in the model input match to rows in the related tables.from sdm import RelatedTables, TableTensor data = RelatedTables( tables={ "users": TableTensor.from_columns( {"user_id": [0, 1]}, stypes={"user_id": "id"}, ), "orders": TableTensor.from_columns( { "user_id": [0, 1], "item_id": [10, 11], }, stypes={ "user_id": "id", "item_id": "id", }, ), "items": TableTensor.from_columns( {"item_id": [10, 11]}, stypes={"item_id": "id"}, ), }, relationships=[ # Foreign key from orders to users: dict(left_table="orders", left_column="user_id", right_table="users", right_column="user_id"), # Foreign key from orders to items: dict(left_table="orders", left_column="item_id", right_table="items", right_column="item_id"), ], task_links=[ # Foreign key in the task table to users: dict(task_column="ENTITY", table="users", table_column="user_id") ], )
- Parameters:
- property schema: RelatedTablesSchema#
The schema of this related context.
- is_same_schema(other: RelatedTables) → bool#
Whether
otherhas the same schema layout.- Parameters:
other (RelatedTables) – The object to compare against.
- Return type:
- to_graphviz(*, hide_columns: bool = False, **kwargs: Any) → graphviz.Graph#
Return a task visualization of the relational schema.
- Parameters:
hide_columns (bool) – Whether to hide column name descriptions.
**kwargs (Any) – Additional keyword arguments passed to
graphviz.Graph.
- Return type: