Skip to content

Commit

Permalink
Add namedtuple header detection closing #91
Browse files Browse the repository at this point in the history
  • Loading branch information
EntilZha committed Feb 1, 2017
1 parent 7cd7906 commit 52c1c96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions functional/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,8 @@ def tabulate(self, n=None, headers=(), tablefmt="simple", floatfmt="g", numalign
rows = self.list()
else:
rows = self.take(n).list()
if len(headers) == 0 and is_namedtuple(rows[0]):
headers = rows[0]._fields
return tabulate(rows, headers=headers, tablefmt=tablefmt, floatfmt=floatfmt,
numalign=numalign, stralign=stralign, missingval=missingval)

Expand Down
4 changes: 4 additions & 0 deletions functional/test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,10 @@ class NotTabulatable(object):
sequence = seq(NotTabulatable(), NotTabulatable(), NotTabulatable())
self.assertEqual(sequence.tabulate(), None)

def test_tabulate_namedtuple(self):
sequence_tabulated = seq([Data(1, 2), Data(6, 7)]).tabulate()
self.assertEqual(sequence_tabulated, ' x y\n--- ---\n 1 2\n 6 7')

def test_repr_max_lines(self):
sequence = seq.range(200)
self.assertEqual(len(repr(sequence)), 395)
Expand Down

0 comments on commit 52c1c96

Please sign in to comment.