Skip to content

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

Open

Description

@gbus

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?

Activity

  1. coltonpaquette commented on Nov 24, 2023

    @coltonpaquette

    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
    --------------  ---
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions