Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/maketables/etable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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.
Expand Down Expand Up @@ -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
)
Expand Down
Loading