Stop French "sept" being simplified to 7 when it means September - #1353
Open
DMZ22 wants to merge 1 commit into
Open
Stop French "sept" being simplified to 7 when it means September#1353DMZ22 wants to merge 1 commit into
DMZ22 wants to merge 1 commit into
Conversation
"sept" is both the abbreviation for "septembre" and the French word for seven, and simplifications are applied to the whole string before month names are looked up, so the number always won: with French pinned, "1 sept. 2024" parsed as 1 July 2024. The trailing dot cannot be used to tell the two apart, because sanitize_date() strips it before the locale is consulted -- "1 sept 2024" was equally wrong. Instead, only simplify "sept" to 7 where it is a quantity, that is when it is followed by a French duration unit or by a clock time. "a" (for "annee") is accepted as a unit only when no number follows it, because the preposition "a" loses its accent during normalization and would otherwise swallow the month in "3 sept a 14h30". Regenerated fr.py with dateparser_scripts/write_complete_data.py.
AdrianAtZyte
approved these changes
Jul 27, 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.
Closes #1285.
septis both the abbreviation forseptembreand the French word for seven. Simplifications are applied to the whole string inLocale.translate()before the dictionary is consulted, so by the time month names are looked up the tokenseptno longer exists — it is already7. The month translation can never win.The dot is not the discriminator.
sanitize_date()runsRE_SANITIZE_PERIOD.sub("", …)before the locale is consulted, so1 sept. 2024and1 sept 2024are the same string by then — both were wrong. A fix keyed onsept.cannot work.I also want to flag why this looks fine in casual testing: without an explicit locale it already returns September, because language detection picks
enand the French simplification never runs. The existing case attests/test_date_parser.py:63("11 sept. 2014") passes for exactly that reason. Only the locale-pinned path — the one you use when you know the language — is broken.The change
Only simplify
septto7where it is a quantity: followed by a French duration unit or a clock time. The unit list is taken from the French data itself (année/ans/an,mois/m,semaine/sem,jour/j,heure/h,minute/min,seconde/s).One subtlety worth its own note.
ais a valid abbreviation forannée, butnormalize_unicode()runs before simplification, so the prepositionàhas already becomeaby then. Accepting a bareaas a unit therefore re-breaks3 sept à 14h30; rejecting it outright breaksil y a sept a. The rule I settled on acceptsaas a unit only when no number follows it, which keeps both:Verification
The regression surface here is the real risk, and it is almost entirely untested —
tests/test_freshness_date_parser.pyhas no French cases at all, so simply deleting thesept: '7'entry would leave CI green while silently breaking every "seven " phrase. I checked that explicitly: I built a 30-phrase set of cardinal-seven inputs (il y a sept jours,sept semaines,dans sept heures,sept:30,sept ans et 3 mois, the single-letter forms, …), recorded their output before the change, and compared after.pytest tests --ignore=tests/test_date.pygives 3 failed / 23793 passed before and 3 failed / 23802 passed after — same three failures (test_parse_negative_timestamp_*, a Windows-onlyOSErrorindatetime.fromtimestamp, unrelated), plus the 9 new params.tests/test_dateparser_data_integrity.pypasses, so the regeneratedfr.pymatches the YAML.ruffandruff-format(v0.9.3, matching.pre-commit-config.yaml) are clean.fr.pywas regenerated withdateparser_scripts/write_complete_data.pyrather than hand-edited.