From 4d1582d0770a9da6c6aa3528d13646e723529b17 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Mon, 2 Nov 2020 00:42:05 +0200 Subject: [PATCH] Fix report_table as list of rows --- examples/reporting/pandas_reporting.py | 16 +++++++++++++--- trains/utilities/plotly_reporter.py | 7 ++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/examples/reporting/pandas_reporting.py b/examples/reporting/pandas_reporting.py index 5f34d969..42ff8480 100644 --- a/examples/reporting/pandas_reporting.py +++ b/examples/reporting/pandas_reporting.py @@ -29,14 +29,24 @@ def report_table(logger, iteration=0): # Report table - CSV from path 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(): # 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, # You can also call Task.current_task().get_logger() from anywhere in your code. diff --git a/trains/utilities/plotly_reporter.py b/trains/utilities/plotly_reporter.py index d0a09823..d9fc5f06 100644 --- a/trains/utilities/plotly_reporter.py +++ b/trains/utilities/plotly_reporter.py @@ -485,7 +485,12 @@ def create_plotly_table(table_plot, title, series, layout_config=None): :param layout_config: additional configuration layout :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] cells_values = [list(i) for i in zip(*table_plot[1:])] else: