Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix TableSet.print_structure for nested tablesets, #765 #776

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading