From 88dc86aa20a99baad8303e3a36f4c6d43b7bd04f Mon Sep 17 00:00:00 2001 From: anna-charlotte Date: Wed, 22 Mar 2023 19:23:55 +0100 Subject: [PATCH] fix: doc summary for dict and set attributes Signed-off-by: anna-charlotte --- docarray/display/document_summary.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docarray/display/document_summary.py b/docarray/display/document_summary.py index fd0598ded32..69b63761265 100644 --- a/docarray/display/document_summary.py +++ b/docarray/display/document_summary.py @@ -137,14 +137,26 @@ def __rich_console__( table.add_row(col_1, text.Text(col_2)) elif isinstance(value, AbstractTensor): table.add_row(col_1, TensorDisplay(tensor=value)) - elif isinstance(value, (tuple, list)): + elif isinstance(value, (tuple, list, set)): + value_list = list(value) col_2 = '' - for i, x in enumerate(value): + for i, x in enumerate(value_list): if len(col_2) + len(str(x)) < 50: - col_2 = str(value[:i]) + col_2 = str(value_list[: i + 1]) else: - col_2 = f'{col_2[:-1]}, ...] (length: {len(value)})' + col_2 = f'{col_2[:-1]}, ...] (length: {len(value_list)})' break + + if type(value) == tuple: + col_2 = col_2.replace('[', '(', 1).replace(']', ')', -1) + if type(value) == set: + col_2 = col_2.replace('[', '{', 1).replace(']', '}', -1) + + table.add_row(col_1, text.Text(col_2)) + elif isinstance(value, dict): + col_2 = f'{value}' + if len(col_2) > 50: + col_2 = f'{col_2[: 50]}' + ' ... } ' + f'(length: {len(value)})' table.add_row(col_1, text.Text(col_2)) if table.rows: