Skip to content

fix(transliterate): romanize royin words containing ฤ - #1473

Merged
wannaphong merged 2 commits into
PyThaiNLP:mainfrom
Sanjays2402:fix/royin-ru-indexerror
Aug 4, 2026
Merged

fix(transliterate): romanize royin words containing ฤ#1473
wannaphong merged 2 commits into
PyThaiNLP:mainfrom
Sanjays2402:fix/royin-ru-indexerror

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

What do these changes do

Make romanize(..., engine="royin") handle words containing ฤ (U+0E24) instead of raising IndexError, and add a regression test for them.

What was wrong

_romanize() built its consonant list with _RE_CONSONANT, which is compiled from thai_consonants and therefore does not match ฤ. _replace_consonants(), however, treats every key of _CONSONANTS — which does include ฤ — as a consonant and advances its index for each one. On a word containing ฤ the index ran past the end of the list, so romanize("ฤดู", engine="royin") raised IndexError: string index out of range.

How this fixes it

The consonant list is now built with the same membership test the loop uses (c in _CONSONANTS), keeping the two in sync and letting ฤ romanize through its existing _CONSONANTS entry. ฤก→rueok, ฤดู→rueadu, ฤทธิ์→rueot; words without ฤ are byte-identical to before, including ฤ words that did not crash (พฤษภาคม, อังกฤษ, พฤหัสบดี, นฤมล, ทฤษฎี).

Fixes #1444

Your checklist for this pull request

  • Passed code styles and structures
  • Passed code linting checks and unit test

test_romanize_royin_ru was added to tests/core/test_transliterate.py beside the existing royin tests; it fails without the source fix (the reported IndexError) and passes with it. tests/core/test_transliterate.py passes in full, and ruff check is clean on both changed files.

This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

romanize(..., engine="royin") raised IndexError on words containing ฤ
(U+0E24), e.g. ฤดู, ฤก, ฤทธิ์.

_romanize() built its consonant list with _RE_CONSONANT, which matches
only thai_consonants and so excludes ฤ, while _replace_consonants()
treats every key of _CONSONANTS - including ฤ - as a consonant and
advances its index for each one. The two went out of sync and the index
ran past the end of the list.

The consonant list is now built with the same membership test the loop
uses, so ฤ is romanized through its existing _CONSONANTS entry.

Adds RU_TESTS and test_romanize_royin_ru to
tests/core/test_transliterate.py.

Closes PyThaiNLP#1444

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug in the royin RTGS romanization engine where words containing ฤ (U+0E24) could crash with an IndexError, and adds regression coverage to ensure these words romanize correctly going forward.

Changes:

  • Build the consonant list in _romanize() using _CONSONANTS key membership to keep indexing consistent with _replace_consonants().
  • Add regression tests for representative ฤ-containing words and their expected romanizations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pythainlp/transliterate/royin.py Aligns consonant collection with _replace_consonants() behavior to prevent IndexError on ฤ words.
tests/core/test_transliterate.py Adds regression tests for ฤ-containing words to validate correct royin romanization.

Comment thread tests/core/test_transliterate.py Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@wannaphong wannaphong added the bug bugs in the library label Aug 3, 2026
@wannaphong
wannaphong merged commit 395c4e5 into PyThaiNLP:main Aug 4, 2026
5 checks passed
@wannaphong

Copy link
Copy Markdown
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug bugs in the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IndexError on Thai words containing ฤ (U+0E24)

3 participants