Skip to content

Fix incorrect date parsing for multi-word number representations#1280

Merged
serhii73 merged 4 commits intomasterfrom
fix/1260
Jul 24, 2025
Merged

Fix incorrect date parsing for multi-word number representations#1280
serhii73 merged 4 commits intomasterfrom
fix/1260

Conversation

@serhii73
Copy link
Copy Markdown
Collaborator

@serhii73 serhii73 commented Jul 23, 2025

Close #1260

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.49%. Comparing base (f69e9b2) to head (56a7bb6).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1280      +/-   ##
==========================================
+ Coverage   97.47%   97.49%   +0.01%     
==========================================
  Files         234      234              
  Lines        2776     2793      +17     
==========================================
+ Hits         2706     2723      +17     
  Misses         70       70              

☔ View full report in Codecov by Sentry.
📢 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.

@serhii73 serhii73 requested a review from Copilot July 24, 2025 11:50
@serhii73 serhii73 changed the title [WIP] Fix incorrect date parsing for multi-word number representations Fix incorrect date parsing for multi-word number representations Jul 24, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes incorrect date parsing for multi-word number representations in Russian by enhancing the date parsing logic to properly handle compound ordinal numbers (e.g., "двадцать первое" = "twenty first" = 21st).

  • Expands Russian language simplification patterns to include ordinal forms and additional grammatical cases for numbers 1-50
  • Implements specialized processing logic for Russian compound ordinals that mathematically combines separate number components
  • Adds comprehensive test coverage for multi-word date expressions in Russian (20th-31st of various months)

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/test_search.py Adds parameterized test cases for Russian multi-word date expressions
dateparser_data/supplementary_language_data/date_translation_data/ru.yaml Expands Russian number simplification patterns with ordinal forms and grammatical cases
dateparser/languages/locale.py Implements Russian-specific compound ordinal processing logic
dateparser/data/date_translation_data/ru.py Updates compiled Russian translation data with expanded number patterns
Comments suppressed due to low confidence (1)

tests/test_search.py:1110

  • The test cases only cover February and March dates. Consider adding test cases for other months to ensure the parsing logic works consistently across all months.
                text="Ужасное событие произошло в тот день. Двадцатое февраля. Вспоминаю тот день с ужасом.",

Comment on lines +457 to +458
number_pair_pattern = r"\b(\d+)\s+(\d+)\b"
date_string = re.sub(number_pair_pattern, replace_number_pairs, date_string)
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

The regex pattern should be compiled as a module-level constant since it's used repeatedly, which would improve performance and maintainability.

Suggested change
number_pair_pattern = r"\b(\d+)\s+(\d+)\b"
date_string = re.sub(number_pair_pattern, replace_number_pairs, date_string)
date_string = re.sub(NUMBER_PAIR_PATTERN, replace_number_pairs, date_string)

Copilot uses AI. Check for mistakes.
(
expected_text,
datetime.datetime(
datetime.datetime.now().year, expected_month, expected_day, 0, 0
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

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

Using datetime.datetime.now().year in tests can make them non-deterministic and fail when run across year boundaries. Consider using a fixed year value instead.

Suggested change
datetime.datetime.now().year, expected_month, expected_day, 0, 0
2025, expected_month, expected_day, 0, 0

Copilot uses AI. Check for mistakes.
@serhii73 serhii73 requested review from Gallaecio and wRAR July 24, 2025 12:11
@serhii73 serhii73 merged commit abf7130 into master Jul 24, 2025
18 checks passed
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.

Incorrect date parsing for multi-word number representations

4 participants