Skip to content

Parse Arabic and Persian dates typed with each other’s yeh and kaf - #1423

Merged
AdrianAtZyte merged 8 commits into
scrapinghub:masterfrom
AdrianAtZyte:persian-arabic-yeh
Oct 22, 2026
Merged

AdrianAtZyte merged 8 commits into
scrapinghub:masterfrom
AdrianAtZyte:persian-arabic-yeh

Conversation

@AdrianAtZyte

Copy link
Copy Markdown
Member

Resolves #1212

@codspeed

codspeed Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 10 untouched benchmarks


Comparing AdrianAtZyte:persian-arabic-yeh (a1792af) with master (6d32a3e)

Open in CodSpeed

@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.08%. Comparing base (6d32a3e) to head (a1792af).

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.
📢 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.

@AdrianAtZyte
AdrianAtZyte marked this pull request as ready for review September 23, 2026 13:03

@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.

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 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.

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. When languages is given together with a region, languages without a valid lang-region locale are now added as plain lang locales instead of being dropped. languages=['es','de'], region='MX' used to yield only es-MX and now yields es-MX plus de, so parse results or the detected locale can change for existing callers. test_region_falls_back_to_given_languages_without_it encodes 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-* and fa locale now makes two is_applicable calls per non-matching string, with about 20 Arabic regional locales scanned on parse() 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 overrides use_given_order, and try_previous_locales ignores _native.
  • Each ar-*/fa Locale builds a second full Locale eagerly and tells it apart by info['name'] += '~native'; a lazy _native with an explicit cache key would be sturdier.
  • The explicit Persian-yeh entry تشرین الأول was removed; 10 تشرین الأول 2020 returns 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_applicability builds 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 or IGNORE_SURROUNDING_TEXT).

@AdrianAtZyte
AdrianAtZyte merged commit 78b2fc2 into scrapinghub:master Oct 22, 2026
19 checks passed
serhii73 added a commit to AdrianAtZyte/dateparser that referenced this pull request Nov 4, 2026
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]>
serhii73 added a commit that referenced this pull request Nov 4, 2026
* 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]>
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.

Iran/Persian/Farsi date parsing fail

2 participants