From 4d03c0bf22a7a676194188ee8ef7c028c4620cbf Mon Sep 17 00:00:00 2001 From: leostimpfle Date: Sun, 15 Mar 2026 15:47:49 +0000 Subject: [PATCH 1/2] Distinguish comma delimter from thousand separator --- src/maketables/etable.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/maketables/etable.py b/src/maketables/etable.py index bc0b377..4589962 100644 --- a/src/maketables/etable.py +++ b/src/maketables/etable.py @@ -805,6 +805,14 @@ def _relabel_index(index, labels=None, stats_labels=None): return index +def _is_valid_format_spec(spec: str) -> bool: + """Check if spec is a valid Python format specification.""" + try: + format(0.0, spec) + except (ValueError, TypeError): + return False + return True + def _parse_coef_fmt(coef_fmt: str, custom_stats: dict, available_columns: set): """ Parse the coef_fmt string with format specifiers and star markers. @@ -893,9 +901,15 @@ def _parse_coef_fmt(coef_fmt: str, custom_stats: dict, available_columns: set): format_start = after_token_pos + 1 format_end = format_start # Stop at delimiters: space, newline, brackets, backslash, comma, or * + # A comma is allowed when it is a valid grouping option + # (thousands separator) rather than a literal delimiter. while ( format_end < len(coef_fmt) - and coef_fmt[format_end] not in [" ", "\n", "(", ")", "[", "]", "\\", ",", "*"] + and coef_fmt[format_end] not in [" ", "\n", "(", ")", "[", "]", "\\", "*"] + and ( + coef_fmt[format_end] != "," + or _is_valid_format_spec(coef_fmt[format_start:format_end + 1]) + ) and not any( coef_fmt[format_end:].startswith(t) for t in all_tokens ) From 9f4b208029f9604bcc63d4a4416350e6cbaf996c Mon Sep 17 00:00:00 2001 From: leostimpfle Date: Sun, 15 Mar 2026 15:56:54 +0000 Subject: [PATCH 2/2] Narrow exception --- src/maketables/etable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maketables/etable.py b/src/maketables/etable.py index 4589962..78687b7 100644 --- a/src/maketables/etable.py +++ b/src/maketables/etable.py @@ -809,7 +809,7 @@ def _is_valid_format_spec(spec: str) -> bool: """Check if spec is a valid Python format specification.""" try: format(0.0, spec) - except (ValueError, TypeError): + except ValueError: return False return True