Skip to content

Commit

Permalink
Merge pull request #776 from wireservice/765-print_structure-nested-t…
Browse files Browse the repository at this point in the history
…ableset

fix: Fix TableSet.print_structure for nested tablesets, #765
  • Loading branch information
jpmckinney authored Apr 27, 2024
2 parents 8eee14a + 72e83ef commit 4001e97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
-------------------------

Expand Down
16 changes: 13 additions & 3 deletions agate/tableset/print_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down

0 comments on commit 4001e97

Please sign in to comment.