Repository navigation
Conversation
Codecov Report
@@ Coverage Diff @@
## master #786 +/- ##
==========================================
- Coverage 98.37% 98.37% -0.01%
==========================================
Files 231 231
Lines 2522 2520 -2
==========================================
- Hits 2481 2479 -2
Misses 41 41
Continue to review full report at Codecov.
|
| return | ||
| raise ValueError('Unable to parse date from: %s' % datestring) | ||
|
|
||
| datestring = datestring.replace(':', '') | ||
| if not datestring: | ||
| return | ||
| raise ValueError("Empty string") |
There was a problem hiding this comment.
Does this change the current behaviour? Is it a breaking change?
There was a problem hiding this comment.
As explained, in the PR description: "I made some changes in the tests as it was expected to return None when finding invalid inputs but it should return an empty date_data ({'date_obj': None, 'period': ...}) or raising an exception and I preferred the second approach". This decision was made to make it behave more similar to the absolute-time parser.
About the "breaking change", this PR has been tagged as it. The full implementation is a breaking change.
| 'relative-time', | ||
| 'custom-formats', | ||
| 'absolute-time', | ||
| 'no-spaces-time', |
There was a problem hiding this comment.
This should probably be documented in docs/usage.rst (the other parsers are listed there).
There was a problem hiding this comment.
You are totally right! I added it!
|
Hey @Gallaecio @skyuchukov-bp , thank you for the feedback! I added some information in the docs. On the other hand, as I have been able to play around with only the Of course, this is a breaking change, but it's ok as we are going to release a new major version. People will be able to use it by doing: >>> from dateparser_data.settings import default_parsers
>>> dateparser.parse('2016020417:10', settings={'PARSERS': default_parsers + ['no-spaces-time']})Let me know what you think about this point. This will fix the well-known issue with the >>> dateparser.parse('2017', settings={'STRICT_PARSING': True}) |
|
I also checked the #582 issue and it fixes a lot of the cases: For example, for this string (created from the second comment in #582): text = '32° 34’S and 123° and 6005 and 000 and of 629 and >21 and 3533 and 538400'Last released version: >>> search_dates(text)
[('32° 34’S', datetime.datetime(2020, 9, 17, 10, 57, 48, 787596)),
('123°', datetime.datetime(1900, 1, 1, 1, 2, 3)),
('6005', datetime.datetime(6005, 1, 1, 0, 0)),
('000', datetime.datetime(1900, 1, 1, 0, 0)),
('629', datetime.datetime(1900, 1, 1, 6, 2, 9)),
('>21', datetime.datetime(1900, 1, 21, 0, 0)),
('3533', datetime.datetime(3533, 1, 21, 0, 0)),
('538400', datetime.datetime(8400, 5, 3, 0, 0))]
>>> search_dates(text, settings={'STRICT_PARSING': True})
[('32° 34’S', datetime.datetime(2020, 9, 17, 10, 58, 28, 836995)),
('123°', datetime.datetime(1900, 1, 1, 1, 2, 3)),
('6005', datetime.datetime(2000, 6, 5, 0, 0)),
('000', datetime.datetime(1900, 1, 1, 0, 0)),
('629', datetime.datetime(1900, 1, 1, 6, 2, 9)),
('>21', datetime.datetime(1900, 1, 1, 2, 1)),
('3533', datetime.datetime(2033, 3, 5, 0, 0)),
('538400', datetime.datetime(8400, 5, 3, 0, 0))]this PR: >>> search_dates(text)
[('32° 34’S', datetime.datetime(2020, 9, 17, 11, 4, 21, 207745)),
('6005', datetime.datetime(6005, 9, 17, 0, 0)),
('>21', datetime.datetime(6005, 9, 21, 0, 0)),
('3533', datetime.datetime(3533, 9, 21, 0, 0))]
>>> search_dates(text, settings={'STRICT_PARSING': True})
[('32° 34’S', datetime.datetime(2020, 9, 17, 11, 4, 58, 313809))] |
|
Looks good to me. |
|
thank you guys! |
Fixes: #751, fixes #713, #769, reduce false positives in: #582
I separated the
no-spaces-timeparser from theabsolute-timeparser. I made some changes in the tests as it was expected to return None when finding invalid inputs but it should return an emptydate_data({'date_obj': None, 'period': ...}) or raising an exception and I preferred the second approach.From what I did I thought that we should improve the parsers API, so I opened a new issue: #785