Tables

View as Markdown

After you have connected your source tables and applied any necessary transformations, you can construct a Graph consisting of Table objects.

A Kumo Graph represents a connected set of Tables. Each Table fully specifies the metadata of its underlying SourceTable (including selected columns, data types, semantic types, and relational constraints) for modeling purposes.

Creating Tables from Source

You can construct a Table from a SourceTable in multiple ways. The simplest approach is to call from_source_table():

1# NOTE if `columns` is not specified, all source columns are included:
2customer = kumo.Table.from_source_table(
3 source_table=customer_src,
4 primary_key='CustomerID',
5).infer_metadata()
6
7transaction = kumo.Table.from_source_table(
8 source_table=transaction_src,
9 time_column='InvoiceDate',
10).infer_metadata()

Inspecting Table Metadata

To verify the inferred metadata, call the metadata property:

1>>> print(customer.metadata)
2
3+----+------------+---------+---------+------------------+------------------+----------------------+
4| | name | dtype | stype | is_primary_key | is_time_column | is_end_time_column |
5|----|------------+---------+---------+------------------+------------------+----------------------|
6| 0 | CustomerID | float64 | ID | True | False | False |
7+----+------------+---------+---------+------------------+------------------+----------------------+

To adjust individual column properties, access columns by name:

Building Tables from Scratch

You can also define a table manually, with Kumo inferring metadata for any partially specified columns:

1stock = kumo.Table(
2 source_table=stock_src,
3 columns=[dict(name='StockCode', stype='ID')], # will infer dtype='string'
4 primary_key='StockCode',
5).infer_metadata()
6
7# Validate the table's correctness:
8stock.validate(verbose=True)

Modifying Table Metadata

Table exposes the same methods to inspect and adjust metadata regardless of how it was created:

1# Set and access a data type for a column ("StockCode") in the stock table:
2stock.column("StockCode").dtype = "string"
3print(stock["StockCode"].dtype)

The column() method returns a Column object containing that column’s metadata.

You can also modify the primary key, add or remove columns:

1# Set the primary key:
2table.primary_key = 'new_primary_key'
3
4# Unset (remove) the primary key:
5table.primary_key = None
6
7# Check if a table has a primary key:
8print(f"Table has primary key? {table.has_primary_key()}")
9
10# Add a new column:
11table.add_column(name="col", dtype="int")
12
13# Edit the column's semantic type:
14table.column("col").stype = "categorical"
15
16# Remove a column:
17table.remove_column("col")

Table Identity

Tables do not have names in the Kumo Fine-Tune SDK: a table is fully specified by its configuration in code. Two notebooks using the same table configuration refer to the same table object in the Kumo backend. Editing a table creates a new object in the backend, independent of other tables.

Fully specify your tables in production code to avoid unexpected re-inference of metadata.