Repository navigation
Parse Arabic and Persian dates typed with each other’s yeh and kaf - #1423
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1423 +/- ##
==========================================
+ Coverage 99.05% 99.08% +0.03%
==========================================
Files 239 239
Lines 3900 3928 +28
==========================================
+ Hits 3863 3892 +29
+ Misses 37 36 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
serhii73
left a comment
There was a problem hiding this comment.
Thanks, the yeh/kaf mapping looks right to me, and the old _construct_locales/zip_longest misalignment really needed fixing: on master, languages=['ar', 'de', 'es'], region='MX' loads es-MX with another language's data. The new loop does drop one case that used to work, though: a region for which the language has no separate locale because the base locale already is that region:
import dateparser
dateparser.parse("5 de março de 2020", languages=["pt"], region="BR")
dateparser.parse("5 mars 2020", languages=["fr"], region="FR")
dateparser.parse("5 marzo 2020", languages=["es"], region="ES")
dateparser.parse("5. März 2020", languages=["de"], region="DE")
# master: datetime.datetime(2020, 3, 5, 0, 0) for each
# PR: None for each (no locale is loaded at all, and no error is raised)Could we fall back to the bare language when language-region is not a known locale?
for language in languages:
locale = f"{language}-{region}" if region else language
if region and not _isvalidlocale(locale):
locale = language
locale_dict[locale] = (language, region)That keeps the misalignment fix, and the calls above work again (ar + IQ still loads ar-IQ). Only test_region_skips_languages_without_it would need to expect ar, de, es-MX. If loading every base language is unwanted when languages is None, the fallback could be limited to explicitly given languages.
Minor: the exact call in #1212, parse('۳ یولیو ۲۰۱۴', languages=['fa']), still returns None, while it now parses with languages=['ar'] or no languages. That seems intended, since یولیو is the Arabic month name, but it may be worth saying so in the issue when it is closed.
serhii73
left a comment
There was a problem hiding this comment.
Code review (claude code-review, at 4623bed). The full suite passes on this head (24667 passed) and I found no wrong date on the PR's own inputs, so I'm approving. One point I'd like the author to decide before merge:
- Unrelated behaviour change in
loader.py. Whenlanguagesis given together with aregion, languages without a validlang-regionlocale are now added as plainlanglocales instead of being dropped.languages=['es','de'], region='MX'used to yield onlyes-MXand now yieldses-MXplusde, so parse results or the detected locale can change for existing callers.test_region_falls_back_to_given_languages_without_itencodes this. It has nothing to do with Arabic/Persian letters, so it would fit better as its own PR, or at least a changelog line.
Non-blocking notes:
- Every
ar-*andfalocale now makes twois_applicablecalls per non-matching string, with about 20 Arabic regional locales scanned onparse()without languages. A prefilter (the string containsیorک) would skip it for most input. letter_variant_locales.append(locale)runs per date string, so a locale can be yielded twice or again after all other locales; deferring variant-only locales also overridesuse_given_order, andtry_previous_localesignores_native.- Each
ar-*/faLocale builds a second full Locale eagerly and tells it apart byinfo['name'] += '~native'; a lazy_nativewith an explicit cache key would be sturdier. - The explicit Persian-yeh entry
تشرین الأولwas removed;10 تشرین الأول 2020returns None on master and here, so it never parsed, but a test or issue would be worthwhile. Other Arabic-script variants (ى/ي,ه/ة) still fail the same way. count_applicabilitybuilds a 4-element list through in-place+=; an explicit tuple would be clearer. Search tests cover only one short ar and fa string (no mixed text, timezone suffix orIGNORE_SURROUNDING_TEXT).
Bring the draft in line with master after "Deprecate instead of remove" (scrapinghub#1556): what it turned back into deprecations moves from "Breaking changes" to "Deprecations", and the removal of the public parse() return tuples is dropped because it no longer happens. Check every other entry against the code and 1.4.3: replace examples that behave the same on 1.4.3 or only under explicit languages with ones that show the change, add the caveats a user would trip over (the ngram strategy of the date_formats argument, the locales of the Levantine month names, the default PREFER_MONTH_OF_YEAR for quarters), drop the English label-and-colon example of scrapinghub#1496 because scrapinghub#1482 undid that change, and add the fixes that had no entry: the region argument (scrapinghub#1423), Russian numeric dates (scrapinghub#1554) and the IndexError of search_dates() for zh-Hans, zh-Hant and yue (scrapinghub#1401, scrapinghub#1407). Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
* Add release notes for 1.5.0 * Update the 1.5.0 release notes Bring the draft in line with master after "Deprecate instead of remove" (#1556): what it turned back into deprecations moves from "Breaking changes" to "Deprecations", and the removal of the public parse() return tuples is dropped because it no longer happens. Check every other entry against the code and 1.4.3: replace examples that behave the same on 1.4.3 or only under explicit languages with ones that show the change, add the caveats a user would trip over (the ngram strategy of the date_formats argument, the locales of the Levantine month names, the default PREFER_MONTH_OF_YEAR for quarters), drop the English label-and-colon example of #1496 because #1482 undid that change, and add the fixes that had no entry: the region argument (#1423), Russian numeric dates (#1554) and the IndexError of search_dates() for zh-Hans, zh-Hant and yue (#1401, #1407). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Serhii A <[email protected]> Co-authored-by: Claude Sonnet 5.5 <[email protected]>
Resolves #1212