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

When using maxcolwidths in a column that contains None values, tabulate crashes with "NoneType takes no arguments" #312

Open
gschizas opened this issue Feb 27, 2024 · 6 comments · May be fixed by #313

Comments

@gschizas
Copy link

Sample script:

from tabulate import tabulate
table = [["spam", 41.9999], ["eggs", "451.0"], ["sausages", None]]
print(tabulate(table, headers='keys', tablefmt='plain'))
print(tabulate(table, headers='keys', tablefmt='plain', maxcolwidths=40))

The last line leads to this exception:

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    print(tabulate(table, headers='keys', tablefmt='plain', maxcolwidths=40))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "tabulate/__init__.py", line 2061, in tabulate
    list_of_lists = _wrap_text_to_colwidths(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "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

(from version 0.90, in the latest commit only the line numbers change)

This is a simple fix, line 1516 (for v0.9.0) should have another guard, like so:

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

I'll do a PR soon.

@fradeve
Copy link

fradeve commented Mar 15, 2024

Thanks for fixing this! I have the same issue 😄

@tywallis
Copy link

tywallis commented May 6, 2024

I am still having this issue

@gschizas
Copy link
Author

gschizas commented May 9, 2024

I am still having this issue

Well, it hasn't been merged or published, what did you expect? 😄

@RaSan147
Copy link

Thanks good sir

@AdityaMayukhSom
Copy link

I think the pull request is still under review, any updates on the feedback implementation?

@gschizas
Copy link
Author

It is, but at least @astanin has been committing again, so I have some hope.

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

Successfully merging a pull request may close this issue.

5 participants