Documentation
Search…
wandb.data_types.Table
The Table class is used to display and analyze tabular data.
1
Table(
2
columns=None, data=None, rows=None, dataframe=None, dtype=None, optional=(True),
3
allow_mixed_types=(False)
4
)
Copied!
Unlike traditional spreadsheets, Tables support numerous types of data: scalar values, strings, numpy arrays, and most subclasses of wandb.data_types.Media. This means you can embed Images, Video, Audio, and other sorts of rich, annotated media directly in Tables, alongside other traditional scalar values.
This class is the primary class used to generate the Table Visualizer in the UI: https://docs.wandb.ai/guides/data-vis/tables.
Tables can be constructed with initial data using the data or dataframe parameters:
1
import pandas as pd
2
import wandb
3
4
data = {"users": ["geoff", "juergen", "ada"],
5
"feature_01": [1, 117, 42]}
6
df = pd.DataFrame(data)
7
8
tbl = wandb.Table(data=df)
9
assert all(tbl.get_column("users") == df["users"])
10
assert all(tbl.get_column("feature_01") == df["feature_01"])
Copied!
Additionally, users can add data to Tables incrementally by using the add_data, add_column, and add_computed_column functions for adding rows, columns, and columns computed from data in other columns, respectively:
1
import wandb
2
3
tbl = wandb.Table(columns=["user"])
4
5
users = ["geoff", "juergen", "ada"]
6
7
[tbl.add_data(user) for user in users]
8
assert tbl.get_column("user") == users
9
10
def get_user_name_length(index, row): return {"feature_01": len(row["user"])}
11
tbl.add_computed_columns(get_user_name_length)
12
assert tbl.get_column("feature_01") == [5, 7, 3]
Copied!
Tables can be logged directly to runs using run.log({"my_table": table}) or added to artifacts using artifact.add(table, "my_table"):
1
import numpy as np
2
import wandb
3
4
wandb.init()
5
6
tbl = wandb.Table(columns=["image", "label"])
7
8
images = np.random.randint(0, 255, [2, 100, 100, 3], dtype=np.uint8)
9
labels = ["panda", "gibbon"]
10
[tbl.add_data(wandb.Image(image), label) for image, label in zip(images, labels)]
11
12
wandb.log({"classifier_out": tbl})
Copied!
Tables added directly to runs as above will produce a corresponding Table Visualizer in the Workspace which can be used for further analysis and exporting to reports.
Tables added to artifacts can be viewed in the Artifact Tab and will render an equivalent Table Visualizer directly in the artifact browser.
Tables expect each value for a column to be of the same type. By default, a column supports optional values, but not mixed values. If you absolutely need to mix types, you can enable the allow_mixed_types flag which will disable type checking on the data. This will result in some table analytics features being disabled due to lack of consistent typing.
Arguments
Text
columns
(List[str]) Names of the columns in the table. Defaults to ["Input", "Output", "Expected"].
data
(List[List[any]]) 2D row-oriented array of values.
dataframe
(pandas.DataFrame) DataFrame object used to create the table. When set, data and columns arguments are ignored.
optional
(Union[bool,List[bool]]) Determines if None values are allowed. Default to True - If a singular bool value, then the optionality is enforced for all columns specified at construction time - If a list of bool values, then the optionality is applied to each column - should be the same length as columns applies to all columns. A list of bool values applies to each respective column.
allow_mixed_types
(bool) Determines if columns are allowed to have mixed types (disables type validation). Defaults to False

Methods

add_column

1
add_column(
2
name, data, optional=(False)
3
)
Copied!
Add a column of data to the table.
Arguments name: (str) - the unique name of the column data: (list | np.array) - a column of homogenous data optional: (bool) - if null-like values are permitted

add_computed_columns

1
add_computed_columns(
2
fn
3
)
Copied!
Adds one or more computed columns based on existing data
Args
Text
fn
A function which accepts one or two parameters, ndx (int) and row (dict), which is expected to return a dict representing new columns for that row, keyed by the new column names. ndx is an integer representing the index of the row. Only included if include_ndx is set to True. row is a dictionary keyed by existing columns

add_data

1
add_data(
2
*data
3
)
Copied!
Add a row of data to the table. Argument length should match column length

add_row

1
add_row(
2
*row
3
)
Copied!

cast

1
cast(
2
col_name, dtype, optional=(False)
3
)
Copied!
Casts a column to a specific type
Arguments
Text
col_name
(str) - name of the column to cast
dtype
(class, wandb.wandb_sdk.interface._dtypes.Type, any) - the target dtype. Can be one of normal python class, internal WB type, or an example object (eg. an instance of wandb.Image or wandb.Classes)
optional
(bool) - if the column should allow Nones

get_column

1
get_column(
2
name, convert_to=None
3
)
Copied!
Retrieves a column of data from the table
Arguments name: (str) - the name of the column convert_to: (str, optional) - "numpy": will convert the underlying data to numpy object

get_index

1
get_index()
Copied!
Returns an array of row indexes which can be used in other tables to create links

index_ref

1
index_ref(
2
index
3
)
Copied!
Get a reference to a particular row index in the table

iterrows

1
iterrows()
Copied!

Iterate over rows as (ndx, row) Yields

index : int The index of the row. Using this value in other WandB tables will automatically build a relationship between the tables row : List[any] The data of the row

set_fk

1
set_fk(
2
col_name, table, table_col
3
)
Copied!

set_pk

1
set_pk(
2
col_name
3
)
Copied!
Class Variables
Text
MAX_ARTIFACT_ROWS
200000
MAX_ROWS
10000