Skip to content

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

@sbconslt

Description

@sbconslt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions