Skip to content

Skip out-of-range month spans during date searches - #1568

Closed
Yongthyuan wants to merge 1 commit into
scrapinghub:masterfrom
Yongthyuan:codex/fix-month-time-span-overflow
Closed

Yongthyuan wants to merge 1 commit into
scrapinghub:masterfrom
Yongthyuan:codex/fix-month-time-span-overflow

Conversation

@Yongthyuan

Copy link
Copy Markdown

With RETURN_TIME_SPAN=True, an out-of-range month span raises ValueError and prevents search_dates() from returning other valid dates in the text:

from datetime import datetime
from dateparser.search import search_dates

search_dates(
    "the past 120000 months. 2024-01-15",
    languages=["en"],
    settings={"RETURN_TIME_SPAN": True, "RELATIVE_BASE": datetime(2026, 11, 3)},
)
# Before: ValueError: year -7974 is out of range
# After: [('2024-01-15', datetime(2024, 1, 15))]

The existing guard handles OverflowError from timedelta arithmetic, but month spans use relativedelta, which raises ValueError when the resulting year is outside the supported range. Catch both exceptions around span generation so an unrepresentable span is omitted while previously parsed dates are retained.

Six regression cases cover past and future month spans, including preservation of another date with both the split and ngram search strategies. All six fail on the unmodified base and pass with the fix.

Validation on macOS arm64, Python 3.12.13, with TZ=UTC:

  • pytest tests/test_long_digit_runs.py tests/test_search.py -q: 462 passed, 31 subtests passed.
  • pytest -q: 25,313 passed, 9 skipped, 4 xfailed, 508 subtests passed.
  • tox -e pre-commit: passed (Ruff lint/format and zizmor).

Other supported Python versions and optional calendar/language-detection dependencies were not tested locally.

Assisted by Codex.

Copilot AI balanced review requested due to automatic review settings November 7, 2026 04:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions github-actions Bot added the spam label Nov 7, 2026
@github-actions github-actions Bot closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants