fix(util): handle Thai zero ("ศูนย์") in text_to_num floating-point parsing - #1503
Merged
Merged
Conversation
bact
approved these changes
Sep 16, 2026
bact
requested changes
Sep 16, 2026
bact suggested passing just the next token instead of threading the full token list and current index through _check_is_thainum; thainum still needed to detect "ศูนย์" coming after "จุด". Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
bact
approved these changes
Sep 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



What do these changes do
Fixes
text_to_num()/words_to_num()/thaiword_to_num()corrupting, mis-parsing, or crashing on any spelled-out Thai floating-point number that contains a zero digit (ศูนย์).What was wrong
ศูนย์(zero) is deliberately excluded from the_digitstable in_check_is_thainum()(comment: "excluded as a special case"), but no special-case handling was ever added downstream. Every check intext_to_num()'s loop that gated on_check_is_thainum(word)[0]therefore treated a bare zero as ordinary text, which:last_index), silently dropping or misplacing digits after a zero, andwords_to_num()/thaiword_to_num(""), raising an unhandledValueError.A naive fix (adding
ศูนย์to the digit table outright) would have false-positived on ordinary Thai words that merely containศูนย์as a prefix, e.g.ศูนย์กลาง(center) orศูนย์รวม(hub), converting them into"0".How this fixes it
_check_is_thainum()now takes optional token-context (tokens,i,thainum) and classifies a bareศูนย์token as numeric only when it's directly adjacent to an active decimal run (preceded byจุดin the accumulator, or immediately followed byจุด). Called without context (its original use classifying dictionary words), behavior is unchanged.text_to_num()computes this classification once per loop iteration (isthainum) instead of re-calling_check_is_thainum()up to three times per token._flush(), which only converts the accumulated buffer throughwords_to_num()when it actually contains a real digit; otherwise it re-emits the buffered words as literal text. This also fixesจุด(decimal point) being misclassified as a numeral unit when it appears with no real digit nearby (e.g.จุดศูนย์กลาง..., "central point"), without needing a separateจุด-specific guard.Verified against all 9 cases from the issue (5 floating-point-with-zero cases + 4 compound-word false-positive guards), plus the existing docstring examples,
tests.core(205 tests) andtests.compact(233 tests total) across Python 3.9/3.10/3.12/3.13 viatox.black,flake8, andruff checkare clean on the changed files.Fixes #1502
Your checklist for this pull request