Skip to content

floatfmt with a padded number and comma separate doesn't align around decimal place #248

Description

@Naton1

Best shown with an example:

>>> x = tabulate.tabulate([[34454634.345], [3.0]], headers=['doesnt work'], floatfmt='17,.4f', tablefmt='simple')                     
>>> print(x)                                                                                                      
           doesnt work
----------------------
  34,454,634.3450
                3.0000

The numbers in the first column aren't aligned by the decimal place.

If I remove the comma (so '17.4f'), it works:

>>> x = tabulate.tabulate([[34454634.345], [3.0]], headers=['doesnt work'], floatfmt='17.4f', tablefmt='simple')               
>>> print(x)
      doesnt work
-----------------
    34454634.3450
           3.0000

I believe it's because the regex at https://github.com/astanin/python-tabulate/blob/master/tabulate/__init__.py#L774 does not support whitespace before the number so _isnumber_with_thousands_separator returns False, although _isnumber works fine for numbers left-padded with whitespace

Activity

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