astanin / python-tabulate

Pretty-print tabular data in Python, a library and a command-line utility. Repository migrated from bitbucket.org/astanin/python-tabulate.
https://pypi.org/project/tabulate/
MIT License
2.1k stars 163 forks source link

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

Open Naton1 opened 1 year ago

Naton1 commented 1 year ago

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