Repository navigation
Support date_formats in search_dates with the ngram strategy - #1436
Merged
AdrianAtZyte merged 7 commits intoOct 26, 2026
Merged
Conversation
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1436 +/- ##
==========================================
+ Coverage 99.09% 99.18% +0.08%
==========================================
Files 239 239
Lines 3997 4052 +55
==========================================
+ Hits 3961 4019 +58
+ Misses 36 33 -3 β View full report in Codecov by Harness. π New features to boost your workflow:
|
AdrianAtZyte
marked this pull request as ready for review
September 23, 2026 15:08
serhii73
approved these changes
Oct 20, 2026
serhii73
left a comment
Collaborator
There was a problem hiding this comment.
Code review (claude code-review, at 107080f; probes run on this head). date_formats is a new opt-in parameter of search_dates (master has none), so nothing that worked before can regress and I'm approving. One limitation deserves attention before this is advertised:
- Formats are not authoritative. Because the longest-first n-gram scan lets a fuzzy parse of an earlier or longer n-gram win,
search_dates('A 15 March 2024 B', strategy='ngram', languages=['en'], date_formats=['%d %B %Y'])returns[('A 15', ...), ('March 2024', ...)], the same as without formats, and'x 2024-03-15 14:30 y'with['%Y-%m-%d %H:%M']returns the span2024-03-15 14:30 ywith a garbage time. The format only helps when the text before it does not fuzzy-parse. Tryingdate_formatsstrictly at every n-gram size first, and falling back to fuzzy parsing afterwards, would fix it.
Non-blocking notes:
- A bare
stror a one-shot iterator fordate_formatsreturns None with a logged warning per candidate (theTypeErroris swallowed by the broadexcept). Validate once up front, turn it into a tuple, and raise on astr. - Candidates are matched against the single-space-joined tokens rather than the original span, so formats with
(,),@,|or multiple spaces never match, silently. - The guard uses truthiness, so
date_formats=[]with the split strategy is accepted; a non-empty list raisesValueError. _parse_candidategains a required positional parameter (give it= None), the docs insearch.pyand__init__.pydiffer, and tests cover only one happy path (no leading words, iterators, multi-token formats,add_detected_languageorRETURN_TIME_SPAN).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #846, resolves #1160