python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

tablefmt="html" outputs empty header row when no data rows

Open sbconslt opened this issue 10 months ago • 0 comments

The HTML table format renderer outputs an empty table header row when there are no data rows. This differs unexpectedly from the default text format renderer which outputs the header row regardless.

>>> from tabulate import tabulate
>>> print(tabulate([], headers=["one", "two", "three"]))
one    two    three
-----  -----  -------
>>> print(tabulate([["a", "b", "c"]], headers=["one", "two", "three"]))
one    two    three
-----  -----  -------
a      b      c
>>> print(tabulate([], headers=["one", "two", "three"], tablefmt="html"))
<table>
<thead>
<tr></tr>
</thead>
<tbody>
</tbody>
</table>
>>> print(tabulate([["a", "b", "c"]], headers=["one", "two", "three"], tablefmt="html"))
<table>
<thead>
<tr><th>one  </th><th>two  </th><th>three  </th></tr>
</thead>
<tbody>
<tr><td>a    </td><td>b    </td><td>c      </td></tr>
</tbody>
</table>

Expected behavior: the table header row should be populated even when there are no data rows, same as the default renderer behaves.

sbconslt avatar Feb 23 '25 21:02 sbconslt