Skip to content

Keep full stops after month and weekday names in search_dates - #1485

Open
AdrianAtZyte wants to merge 4 commits into
scrapinghub:masterfrom
AdrianAtZyte:search-month-abbreviation-full-stop
Open

AdrianAtZyte wants to merge 4 commits into
scrapinghub:masterfrom
AdrianAtZyte:search-month-abbreviation-full-stop

Conversation

@AdrianAtZyte

Copy link
Copy Markdown
Member

Resolves #843

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.95%. Comparing base (9073f25) to head (9546ae2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1485   +/-   ##
=======================================
  Coverage   98.94%   98.95%           
=======================================
  Files         239      239           
  Lines        3521     3530    +9     
=======================================
+ Hits         3484     3493    +9     
  Misses         37       37           

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

@codspeed

codspeed Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks


Comparing AdrianAtZyte:search-month-abbreviation-full-stop (9546ae2) with master (9073f25)

Open in CodSpeed

@AdrianAtZyte
AdrianAtZyte marked this pull request as ready for review September 29, 2026 21:29

@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! This fixes the abbreviations nicely. The problem is that the list also contains the full names, so a sentence that just ends with a weekday or month is no longer split from the next one:

from datetime import datetime
from dateparser.search import search_dates
rb = {"RELATIVE_BASE": datetime(2020, 6, 15, 12)}
search_dates("See you on Monday. 5 people will come.", languages=["en"], settings=rb)
# master: [('on Monday', datetime(2020, 6, 15, 0, 0))]
# PR:     [('on Monday. 5', datetime(2020, 5, 15, 0, 0))]
search_dates("The event is in May. 12 people attended.", languages=["en"], settings=rb)
# master: [('in May', datetime(2020, 5, 15, 0, 0))]
# PR:     [('in May. 12', datetime(2020, 5, 12, 0, 0))]
search_dates("We met on Friday. Yesterday we left.", languages=["en"], settings=rb)
# master: [..., ('on Friday', datetime(2020, 6, 12, 0, 0)), ('Yesterday', datetime(2020, 6, 14, 12, 0)), ...]
# PR:     [..., ('on Friday', datetime(2020, 6, 12, 0, 0))]

Restricting it to the abbreviated forms fixed these for me while keeping all your test cases passing: for each month/weekday key, only use the names that are shorter than the longest one (keys with a single name, like "may", are skipped):

names = []
for key in KNOWN_WORD_TOKENS[: KNOWN_WORD_TOKENS.index("december") + 1]:
    key_names = self.info.get(key, [])
    if len(key_names) > 1:
        longest = max(key_names, key=len)
        names.extend(n for n in key_names if len(n) < len(longest))

Abbreviations that are also ordinary words ("sun", "sat") can still glue sentences ("We sat in the sun. 3 days later we left." now returns nothing), but that is much rarer. Could you add one of the examples above as a test? Also, since _sentence_split runs for every candidate locale during detection, caching the compiled pattern per locale would avoid a slowdown I measured with languages=None (~1.3x).

This branch has not been deployed

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

Add support for month abbreviations in search_dates

2 participants