Repository navigation
Parse Vietnamese May ("Tháng năm"), which the year simplification swallowed - #1497
AdrianAtZyte merged 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1497 +/- ##
=======================================
Coverage 99.23% 99.23%
=======================================
Files 239 239
Lines 4203 4203
=======================================
Hits 4171 4171
Misses 32 32 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
"Tháng năm" is May, but the vi simplification "(?:ngày|năm)\s(\d+)" -> "\1"
treats the "năm" of that month name as the year marker it also is, so
"15 Tháng năm 2020" simplifies to "15 tháng 2020"; "tháng 2" then matches
February and the parse fails on the leftover "020":
"15 Tháng năm 2020" -> "15 february 020" -> None
Require that the "năm" is not preceded by "tháng", which leaves the usual
"ngày 8 tháng 1 năm 2015" and "21 tháng 09 năm 2025" forms untouched
because there the year marker follows a number, not "tháng".
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
a42447e to
0e87adc
Compare
serhii73
left a comment
There was a problem hiding this comment.
Checked the diff, the new tests and the PR description. I reproduced the bug on current master (15 Tháng năm 2020 and Tháng năm 2020 parse to None with languages=["vi"]) and compared the old and new simplification pattern on a set of inputs: the lookbehind changes only the tháng năm <number> forms (also with a non-breaking space) and leaves ngày 8 tháng 1 năm 2015, 21 tháng 09 năm 2025, tháng 5 năm 2020, năm 2020 and tháng năm năm 2020 as they were. The change itself is correct, so approving.
Non-urgent notes:
- CI never ran on this branch: the three workflow runs for this head ended in
failurewith no jobs (a startup failure, not a test failure). The branch also conflicts with current master invi.pyandvi.yaml(merge base from 2026-10-05). After rebasing, please regeneratedateparser/data/date_translation_data/vi.pywithdateparser_scripts/write_complete_data.pyrather than merging it by hand, and let CI run. - The same collision exists for the weekday
thứ năm(Thursday). It is not caused by this PR, but on masterthứ năm 15 tháng 5 2020parses as 2020-05-05 becausenăm 15collapses to15. Adding(?<!thứ\s)next to(?<!tháng\s)would fix it in the same line. - Tests: the PR table lists
Tháng năm 2020, but only the15 Tháng năm 2020form is asserted; the day-less case (and athứ năm 15 ...case if the guard above is added) would be worth covering.
Resolve the conflicts in vi.yaml and vi.py. Master added a second Vietnamese simplification for zero-padded months right after the year-marker rule, so the lookbehind from this branch is kept on the first rule and the new rule is kept as it is. vi.py is identical to what `python -m dateparser_scripts.write_complete_data` generates from the merged vi.yaml. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Problem
In Vietnamese,
nămis both the year marker ("năm 2020" = "year 2020") and the name of the fifth month (Tháng năm= May). Thevisimplification rewrites the year marker:so the
nămthat belongs to the month name is consumed too:Translation shows what happens —
năm 2020collapses to2020, the remainingtháng 2then matches February, and the leftover020is not a usable year:>>> locale.translate("15 Tháng năm 2020") '15 february 020'Every other Vietnamese month parses fine (
Tháng một→ January,Tháng bảy→ July, …); May is the one that collides with the year marker.Fix
Require that the year marker is not directly preceded by
tháng:In the ordinary Vietnamese date forms the year marker follows a number, not
tháng, so they are unaffected:15 Tháng năm 2020None2020-05-15Tháng năm 2020Nonengày 8 tháng 1 năm 20152015-01-082015-01-0821 tháng 09 năm 20252025-09-212025-09-21năm 2020The generated
dateparser/data/date_translation_data/vi.pywas refreshed withdateparser_scripts/write_complete_data.py; the regeneration touches only that one line.Tests
Added the translation case to
tests/test_languages.pyand the parse case to both Vietnamese blocks intests/test_date_parser.py. They fail on master (+ 15 february 020) and pass with the change. Full suite:24266 passed, 6 skipped, 1 xfailed.Related to the broader ambiguity discussed in #33, but this one is not ambiguous:
tháng nămcannot be a year marker.This was found by checking every language's own month and weekday aliases against what
dateparserparses them back to. AI assistance (Claude) was used for that search and to draft this description; I verified the behaviour and ran the tests locally.🤖 Generated with Claude Code