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

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

Open Naton1 opened this issue 2 years ago • 0 comments

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

Naton1 avatar Feb 07 '23 16:02 Naton1