Skip to content

Fix IndexError on name parts that are all combining marks (0.3.1)#20

Merged
atalyaalon merged 1 commit into
mainfrom
fix/capitalize-empty-token-indexerror
Jul 14, 2026
Merged

Fix IndexError on name parts that are all combining marks (0.3.1)#20
atalyaalon merged 1 commit into
mainfrom
fix/capitalize-empty-token-indexerror

Conversation

@atalyaalon

Copy link
Copy Markdown
Contributor

What

capitalize_name_part strips Unicode Mn characters (combining marks, variation selectors) after NFD normalization. When a name part is composed entirely of Mn characters, stripping leaves an empty string, and the code then indexed [0] into it — raising IndexError and crashing normalize_name.

Fix: guard the empty case in _normalize_and_capitalize_single_part (utils/string_manipulation.py) and return the empty result instead of indexing. One-line behavioral guard; real names are unaffected.

Why it matters

Hit in a production backfill classifying every corpus author name. Example: paper_id 274957019, name 彬人 樽󠄀井, which carries an ideographic variation selector U+E0100 (category Mn) between 樽 and 井. The whole batch/pool aborts on the raised exception, so a single pathological name blocks otherwise-clean data.

Repro (before this change)

from sinonym import ChineseNameDetector
ChineseNameDetector().normalize_name("彬人 樽\U000E0100井")   # IndexError: string index out of range

Tests

Added two regression tests in tests/test_bug_report_fixes.py — a unit test on capitalize_name_part (lone combining mark and U+E0100 both return "", while josé→Jose and ou-yang→Ou-Yang are unchanged) and an integration test that normalize_name on the U+E0100 name no longer raises. Full file passes (42), ruff clean.

Note

Verified this crash still reproduces on the 0.4.0 branch (PR #19) at the same site (string_manipulation.py:593), so this guard is worth carrying forward there too. Separately, the embedded variation selector also defeats 0.4.0's Japanese-lexicon match (a distinct classification issue, not addressed here — that belongs in preprocessing).

Bumps 0.3.0 -> 0.3.1.

capitalize_name_part strips Unicode Mn characters (combining marks,
variation selectors) after NFD normalization. A part composed entirely
of Mn chars (e.g. a lone combining acute, or an ideographic variation
selector like U+E0100 embedded in a CJK name) became empty, and the
capitalizer then indexed [0] into the empty string, raising IndexError
and crashing normalize_name. Return the empty result instead.

Seen in production on paper_id 274957019 ('彬人 樽󠄀井', with U+E0100).
Bump 0.3.0 -> 0.3.1.
@atalyaalon
atalyaalon merged commit d91a770 into main Jul 14, 2026
2 checks passed
@atalyaalon
atalyaalon deleted the fix/capitalize-empty-token-indexerror branch July 14, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant