Skip to content

Commit adc5630

Browse files
authored
Merge pull request astanin#139 from saveshodhan/hf-firstrow-fix
fix output for empty list with headers="firstrow"
2 parents ac2bf5e + 46e985e commit adc5630

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

tabulate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,8 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
12531253
headers = rows[0]
12541254
headers = list(map(str, headers)) # headers should be strings
12551255
rows = rows[1:]
1256+
elif headers == "firstrow":
1257+
headers = []
12561258

12571259
headers = list(map(str, headers))
12581260
rows = list(map(list, rows))

test/test_output.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,13 @@ def test_empty_data_without_headers():
21042104
assert_equal(expected, result)
21052105

21062106

2107+
def test_empty_data_with_headers():
2108+
"Output: table with empty data and headers as firstrow"
2109+
expected = ""
2110+
result = tabulate([], headers="firstrow")
2111+
assert_equal(expected, result)
2112+
2113+
21072114
def test_floatfmt():
21082115
"Output: floating point format"
21092116
result = tabulate([["1.23456789"], [1.0]], floatfmt=".3f", tablefmt="plain")

0 commit comments

Comments
 (0)