Skip to content

Parse Vietnamese May ("Tháng năm"), which the year simplification swallowed - #1497

Merged
AdrianAtZyte merged 2 commits into
scrapinghub:masterfrom
yu2971512385-ui:fix/vietnamese-may-year-marker
Nov 5, 2026
Merged

AdrianAtZyte merged 2 commits into
scrapinghub:masterfrom
yu2971512385-ui:fix/vietnamese-may-year-marker

Conversation

@yu2971512385-ui

Copy link
Copy Markdown
Contributor

Problem

In Vietnamese, năm is both the year marker ("năm 2020" = "year 2020") and the name of the fifth month (Tháng năm = May). The vi simplification rewrites the year marker:

simplifications:
    - (?:ngày|năm)\s(\d+[.,]?\d*): \1

so the năm that belongs to the month name is consumed too:

>>> dateparser.parse("15 Tháng năm 2020", languages=["vi"])   # May 15, 2020
None

Translation shows what happens — năm 2020 collapses to 2020, the remaining tháng 2 then matches February, and the leftover 020 is 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:

    - (?<!tháng\s)(?:ngày|năm)\s(\d+[.,]?\d*): \1

In the ordinary Vietnamese date forms the year marker follows a number, not tháng, so they are unaffected:

input before after
15 Tháng năm 2020 None 2020-05-15
Tháng năm 2020 None May 2020
ngày 8 tháng 1 năm 2015 2015-01-08 2015-01-08
21 tháng 09 năm 2025 2025-09-21 2025-09-21
năm 2020 year 2020 year 2020

The generated dateparser/data/date_translation_data/vi.py was refreshed with dateparser_scripts/write_complete_data.py; the regeneration touches only that one line.

Tests

Added the translation case to tests/test_languages.py and the parse case to both Vietnamese blocks in tests/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ăm cannot be a year marker.

This was found by checking every language's own month and weekday aliases against what dateparser parses 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

@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing yu2971512385-ui:fix/vietnamese-may-year-marker (7c8da10) with master (bf51279)

Open in CodSpeed

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.23%. Comparing base (bf51279) to head (7c8da10).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

"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]>
@yu2971512385-ui
yu2971512385-ui force-pushed the fix/vietnamese-may-year-marker branch from a42447e to 0e87adc Compare October 6, 2026 03:00

@serhii73 serhii73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 failure with no jobs (a startup failure, not a test failure). The branch also conflicts with current master in vi.py and vi.yaml (merge base from 2026-10-05). After rebasing, please regenerate dateparser/data/date_translation_data/vi.py with dateparser_scripts/write_complete_data.py rather 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 master thứ năm 15 tháng 5 2020 parses as 2020-05-05 because năm 15 collapses to 15. 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 the 15 Tháng năm 2020 form is asserted; the day-less case (and a thứ 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]>
@AdrianAtZyte
AdrianAtZyte merged commit 90544c0 into scrapinghub:master Nov 5, 2026
19 checks passed
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.

3 participants