in src/smexperiments/tracker.py [0:0]
def log_table(self, title=None, values=None, data_frame=None, output_artifact=True):
"""Record a table of values to an artifact. Rendering in Studio is not currently supported.
Examples
.. code-block:: python
table_data = {
"x": [1,2,3],
"y": [4,5,6]
}
my_tracker.log_table('SampleData',table_data)
# or log a data frame
df = pd.DataFrame(data=table_data)
my_tracker.log_table('SampleData',df)
Args:
title (str, optional): Title of the table. Defaults to None.
values ([type], optional): A dictionary of values. i.e. {"x": [1,2,3], "y": [1,2,3]}.
Defaults to None.
data_frame (DataFrame, optional): Pandas dataframe alternative to values.
Defaults to None.
output_artifact (bool): Determines direction of association to the trial component.
Defaults to output artifact. If False will be an input artifact.
Raises:
ValueError: If values or data_frame are invalid.
"""
if values is None and data_frame is None:
raise ValueError("Either values or data_frame must be supplied.")
if values is not None and data_frame is not None:
raise ValueError("Only one of values or data_frame may be supplied.")
if values is not None:
for key in values:
if "list" not in str(type(values[key])):
raise ValueError(
'Table values should be list. i.e. {"x": [1,2,3]}, instead was ' + str(type(values[key]))
)
if data_frame is not None:
values = _ArtifactConverter.convert_data_frame_to_values(data_frame)
fields = _ArtifactConverter.convert_data_frame_to_fields(data_frame)
else:
fields = _ArtifactConverter.convert_dict_to_fields(values)
data = {"type": "Table", "version": 0, "title": title, "fields": fields, "data": values}
self._log_graph_artifact(title, data, "Table", output_artifact)