question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tabulate fails on empty data with `headers` and `colalign`

See original GitHub issue

It’s possible to pass an empty tabular_data value to tabulate along with headers and this works as expected:

>>> import tabulate
>>> print(tabulate.tabulate([], headers=['foo', 'bar']))
foo    bar
-----  -----
>>> 

However, if colalign values are provided as well, it causes an exception:

>>> print(tabulate.tabulate([], headers=['foo', 'bar'], colalign=('left', 'right')))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/ssd/debian-next/venv/lib/python3.8/site-packages/tabulate.py", line 1494, in tabulate
    aligns[idx] = align
IndexError: list assignment index out of range
>>> 

My expectation is that this would behave as if colalign wasn’t passed since there’s no data to align. I encountered this using tabulate 0.8.7.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Fifty-Ninecommented, Dec 1, 2022

Regarding @Fifty-Nine’s problem, it is fixed in #221 using directlyheadersalign:

Thanks for implementing this! I’ll try it out when I get a chance.

0reactions
eliegoudoutcommented, Nov 27, 2022

@alexwlchan answered to @AlexanderStein already. Regarding @Fifty-Nine’s problem, it is fixed in #221 using directlyheadersalign:

>>> print(tabulate.tabulate([], headers=['foo', 'bar'], headersalign=('left', 'right')))
foo      bar
-----  -----
Read more comments on GitHub >

github_iconTop Results From Across the Web

tabulate fails on empty data with `headers` and `colalign`
Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate. See More. Top ...
Read more >
Issues · astanin/python-tabulate - GitHub
Pretty-print tabular data in Python, a library and a command-line utility. ... tabulate on empty table omits headers for certain output formats.
Read more >
Incorrect column alignment when printing table in Python ...
One possible solution is to rely on some package that has been designed for this purpose, like tabulate: Read more about it!
Read more >
Empty rows raises IndexError with colalign - Bitbucket
A B --- --- foo bar baz qux Traceback (most recent call last): File "test.py", line 11, in...
Read more >
tabulate · PyPI
Pretty-print tabular data in Python, a library and a command-line utility. The main use cases of the library are: printing small tables without...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found