python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

coltype autodetection assumes "0.0" is a float and the table shows "0", instead of the string "0.0"

Open gbus opened this issue 2 years ago • 1 comments

I couldn't find a way to enforce a column type to solve this issue: Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux

>>> t = [["First version", "0.0"], ["Second version", "1.0"], ["Third version", "1.1"]]
>>> print(tabulate(t))
--------------  ---
First version   0
Second version  1
Third version   1.1
--------------  ---

I understand that it is not common to represent 0.0 as string, but I have the unusual requirement to printout versions and the auto-recognition of the column type cuts the ".0". Is there a way to enforce tabulate to keep it as string?

gbus avatar Nov 08 '23 10:11 gbus

Setting disable_numparse to True will give you the result you are looking for:

>>> t = [["First version", "0.0"], ["Second version", "1.0"], ["Third version", "1.1"]]
>>> print(tabulate(t, disable_numparse=True))
--------------  ---
First version   0.0
Second version  1.0
Third version   1.1
--------------  ---

coltonpaquette avatar Nov 24 '23 17:11 coltonpaquette