Fix report_table as list of rows

This commit is contained in:
allegroai 2020-11-02 00:42:05 +02:00
parent 2847cce18d
commit 4d1582d077
2 changed files with 19 additions and 4 deletions

View File

@ -29,14 +29,24 @@ def report_table(logger, iteration=0):
# Report table - CSV from path # Report table - CSV from path
csv_url = "https://raw.githubusercontent.com/plotly/datasets/master/Mining-BTC-180.csv" csv_url = "https://raw.githubusercontent.com/plotly/datasets/master/Mining-BTC-180.csv"
logger.report_table("table csv", "remote csv", iteration=iteration, url=csv_url) logger.report_table("table - csv", "remote csv", iteration=iteration, url=csv_url)
# Report table - Created with list of lists
logger.report_table("table - list of lists",
"List of lists",
iteration=iteration,
table_plot=[
["Last Name", "First Name", "Age"],
["Doe", "John", "25"],
["Smith", "Peter", "30"],
])
def main(): def main():
# Create the experiment Task # Create the experiment Task
task = Task.init(project_name="examples", task_name="pandas table reporting") task = Task.init(project_name="examples", task_name="table reporting")
print('reporting pandas tablea into the plots section') print('reporting pandas tables and python lists as tables into the plots section')
# Get the task logger, # Get the task logger,
# You can also call Task.current_task().get_logger() from anywhere in your code. # You can also call Task.current_task().get_logger() from anywhere in your code.

View File

@ -485,7 +485,12 @@ def create_plotly_table(table_plot, title, series, layout_config=None):
:param layout_config: additional configuration layout :param layout_config: additional configuration layout
:return: dict with plotly data. :return: dict with plotly data.
""" """
if table_plot and isinstance(table_plot, (list, tuple)) and table_plot[0] and isinstance(table_plot[0], (list, tuple)): is_list = isinstance(table_plot, (list, tuple))
if is_list and (not table_plot or not any(table_plot)):
# The list if empty
headers_values = []
cells_values = []
elif is_list and table_plot[0] and isinstance(table_plot[0], (list, tuple)):
headers_values = table_plot[0] headers_values = table_plot[0]
cells_values = [list(i) for i in zip(*table_plot[1:])] cells_values = [list(i) for i in zip(*table_plot[1:])]
else: else: