diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 705cbe39..ea4ecb3b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +1.11.0 - April 27. 2024 +----------------------- + +* fix: Fix :meth:`.TableSet.print_structure` for nested tablesets. (#765) + 1.9.1 - December 21, 2023 ------------------------- diff --git a/agate/tableset/print_structure.py b/agate/tableset/print_structure.py index e8422494..0ceb9295 100644 --- a/agate/tableset/print_structure.py +++ b/agate/tableset/print_structure.py @@ -2,6 +2,15 @@ from agate.data_types import Text from agate.table import Table +from agate.tableset import TableSet + + +def _items(key, value): + if isinstance(value, TableSet): + for k, v in value.items(): + yield from _items(key + (k,), v) + else: + yield key, value def print_structure(self, max_rows=20, output=sys.stdout): @@ -16,10 +25,11 @@ def print_structure(self, max_rows=20, output=sys.stdout): :returns: None """ - max_length = min(len(self.items()), max_rows) + items = list(_items((), self)) + max_length = min(len(items), max_rows) - name_column = self.keys()[0:max_length] - type_column = [str(len(table.rows)) for key, table in self.items()[0:max_length]] + name_column = ['.'.join(key) for key, value in items][0:max_length] + type_column = [str(len(table.rows)) for key, table in items[0:max_length]] rows = zip(name_column, type_column) column_names = ['table', 'rows'] text = Text()