Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sbconslt opened this issue Feb 23, 2025 · 0 comments
Open

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

sbconslt opened this issue Feb 23, 2025 · 0 comments

Comments

@sbconslt
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant