Skip to content

Commit 87a9a4e

Browse files
committed
fix #365 - added a regression test and a fix based on pull request #393
1 parent e13a4d0 commit 87a9a4e

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

tabulate/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,7 @@ def tabulate(
22882288
)
22892289

22902290
if maxheadercolwidths is not None:
2291-
num_cols = len(list_of_lists[0])
2291+
num_cols = len(list_of_lists[0]) if list_of_lists else len(headers)
22922292
if isinstance(maxheadercolwidths, int): # Expand scalar for all columns
22932293
maxheadercolwidths = _expand_iterable(
22942294
maxheadercolwidths, num_cols, maxheadercolwidths

test/test_regression.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,15 @@ def test_empty_table_with_colalign():
548548
]
549549
)
550550
assert_equal(expected, table)
551+
552+
553+
def test_empty_table_with_maxheadercolwidths():
554+
"Regression: empty table with maxheadercolwidths kwarg (issue #365)"
555+
result = tabulate([], headers=["one", "two", "three"], maxheadercolwidths=5)
556+
expected = "\n".join(
557+
[
558+
"one two three",
559+
"----- ----- -------",
560+
]
561+
)
562+
assert_equal(expected, result)

0 commit comments

Comments
 (0)