Skip to content

Commit

Permalink
fix: Fix TableSet.print_structure for nested tablesets, #765
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Oct 4, 2023
1 parent 5998a83 commit cfdc90f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Unreleased

* feat: Lowercase the ``null_values`` provided to individual data types, since all comparisons to ``null_values`` are case-insensitive. (#770)
* feat: :class:`.Mean` works with :class:`.TimeDelta`. (#761)
* fix: Fix :meth:`.TableSet.print_structure` for nested tablesets. (#765)

1.7.1 - Jan 4, 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 cfdc90f

Please sign in to comment.