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

TypeError when cell is None #323

Open
viewercq opened this issue Apr 18, 2024 · 1 comment
Open

TypeError when cell is None #323

viewercq opened this issue Apr 18, 2024 · 1 comment

Comments

@viewercq
Copy link

https://github.com/astanin/python-tabulate/blob/95ae5eb61ef969749e904c90ab429003238d6212/tabulate/__init__.py#L1532C27-L1532C61

  • exception traceback:
   File "C:\Python38\lib\site-packages\tabulate\__init__.py", line 2061, in tabulate
    list_of_lists = _wrap_text_to_colwidths(
  File "C:\Python38\lib\site-packages\tabulate\__init__.py", line 1516, in _wrap_text_to_colwidths
    str(cell) if _isnumber(cell) else _type(cell, numparse)(cell)
TypeError: NoneType takes no arguments
  • reason:
>>> type(None)(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: NoneType takes no arguments
  • solution:

str(cell) if _isnumber(cell) else _type(cell, numparse)(cell)
to
str(cell or '') if _isnumber(cell) or cell is None else _type(cell, numparse)(cell)

@bragov4ik
Copy link

bragov4ik commented May 5, 2024

Seems very related: I get "list index out of range" when there are no elements to tabulate and maxcolwidths is set (e.g. tabulate([],maxcolwidths=[2])):

File ....venv/lib/python3.12/site-packages/tabulate/__init__.py:2054, in tabulate(tabular_data, headers, tablefmt, floatfmt, intfmt, numalign, stralign, missingval, showindex, disable_numparse, colalign, maxcolwidths, rowalign, maxheadercolwidths)
   2051 list_of_lists, separating_lines = _remove_separating_lines(list_of_lists)
   2053 if maxcolwidths is not None:
-> 2054     num_cols = len(list_of_lists[0])
   2055     if isinstance(maxcolwidths, int):  # Expand scalar for all columns
   2056         maxcolwidths = _expand_iterable(maxcolwidths, num_cols, maxcolwidths)

Writing here since basically the same code area/workflow

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

2 participants