diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 12a2950..d3aaafb 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -1021,8 +1021,11 @@ def _afterpoint(string): 2 >>> _afterpoint("123,456.78") 2 + >>> _afterpoint(" 123,456.78 ") + 2 """ + string = string.strip() if _isnumber(string) or _isnumber_with_thousands_separator(string): if _isint(string): return -1 diff --git a/test/test_regression.py b/test/test_regression.py index 9555676..4e5107c 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -211,6 +211,16 @@ def test_column_with_mixed_value_types(): assert_equal(table, expected) +def test_decimal_alignment_with_thousands_separator(): + "Regression: decimal alignment must work for comma-grouped floats (issue #248)" + result = tabulate([[34454634.345], [3.0]], headers=["doesnt work"], floatfmt="17,.4f", tablefmt="simple") + rows = [row for row in result.splitlines() if "." in row and any(c.isdigit() for c in row)] + assert len(rows) == 2 + # the decimal points of both rows must sit in the same column + dot_cols = {row.index(".") for row in rows} + assert len(dot_cols) == 1 + + def test_latex_escape_special_chars(): "Regression: escape special characters in LaTeX output (issue #32)" expected = "\n".join(