Skip to content

Commit bd366f2

Browse files
authored
Corrected when headers or headersalign is too long
1 parent a658c9f commit bd366f2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tabulate/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
15001500
# pad with empty headers for initial columns if necessary
15011501
headers_pad = 0
15021502
if headers and len(rows) > 0:
1503-
headers_pad = len(rows[0]) - len(headers)
1503+
headers_pad = max(0, len(rows[0]) - len(headers))
15041504
headers = [""] * headers_pad + headers
15051505

15061506
return rows, headers, headers_pad
@@ -2234,7 +2234,7 @@ def tabulate(
22342234
# then specific header alignements
22352235
if headersalign is not None:
22362236
assert isinstance(headersalign, Iterable)
2237-
for idx, align in enumerate(headersalign):
2237+
for idx, align in enumerate(headersalign[:len(aligns)]):
22382238
if align == "same": # same as column align
22392239
aligns_headers[headers_pad + idx] = aligns[headers_pad + idx]
22402240
elif align != "global":

0 commit comments

Comments
 (0)