fix afterpoint of numbers with thousand separators resulting in correct decimal alignment #152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #130. It arrises as the function
_afterpoint
fails to recognize numbers with thousand separators. This happens because the function_afterpoint
relies on the function_isnumber
which relies on the built-in functionfloat.__init__
which fails on thousand-separated numbers.I did not change the function
_isnumber
as numbers such as "123,123" are to be aligned as plain text, resulting from the issue #110 and subsequent pulls and tests (test/test_regression.py::test_string_with_comma_between_digits_without_floatfmt_grouping_option
).The solution is therefore implemented in the function
_afterpoint
by checking not only_isnumber
but also a new function__isnumber_with_thousands_separator
which validates floats or ints with thousand separators in [byte]string form. This is done by regexr"^(([+-]?[0-9]{1,3})(?:,([0-9]{3}))*)?(?(1)\.[0-9]*|\.[0-9]+)?$"
which simply optionally matches signs, then the leading group, then separated thousands, and then the decimal part. A decimal part is required if the non-decimal part is empty.The tests were implemented only for the function
tabulate._align_column
.