Repository navigation
Fix incomplete dates when STRICT_PARSING is True - #515
marcosmadr wants to merge 9 commits into
Conversation
Codecov Report
@@ Coverage Diff @@
## master #515 +/- ##
==========================================
- Coverage 95.01% 94.94% -0.08%
==========================================
Files 302 302
Lines 2466 2471 +5
==========================================
+ Hits 2343 2346 +3
- Misses 123 125 +2
Continue to review full report at Codecov.
|
|
Looking at the removed tests, I think we would be removing support for some valid use cases. I wonder if, with a more convoluted solution, we could drop support for unclear scenarios while maintaining support for other cases where less than 6 digits are used but there is only 1 possible date or 1 of the possible dates is the obvious choice. |
|
Hi @Gallaecio , I investigated a bit more to find an alternative approach and I have a suggestion. The thing is that _no_spaces_parser class tries so many date formats that it almost always get an complete date, even if it doesnt look like correct. My best guess would be to limit _no_spaces_parser to parse only the given DATE_ORDER, currently it priorizes the order given but it tries all other combinations. For example:
result = datetime.datetime(2020, 1, 1, 0, 0) IMHO, if DATE_ORDER is specified, it should only try with the given order. For example, the command above would try:
result = None This would fix STRICT_PARSING bug if DATE_ORDER is specified, and I'd go for using the default order if STRICT_PARSING = True and no DATE_ORDER is specified. |
|
Sounds good to me. |
Codecov Report
@@ Coverage Diff @@
## master #515 +/- ##
==========================================
- Coverage 95.01% 94.94% -0.08%
==========================================
Files 302 302
Lines 2466 2471 +5
==========================================
+ Hits 2343 2346 +3
- Misses 123 125 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #515 +/- ##
==========================================
+ Coverage 95.01% 95.02% +0.01%
==========================================
Files 302 302
Lines 2466 2471 +5
==========================================
+ Hits 2343 2348 +5
Misses 123 123
Continue to review full report at Codecov.
|
|
I was about to merge this, but after merging master it stops working... Could you check it? I think that what is happening is that when trying with other locales that have another default order (i.e.: "zh" that has "YMD") it's parsed badly again: >>> dateparser.parse('2017', settings={'STRICT_PARSING': True})
2020-01-07 00:00:00
>>> dateparser.parse('2017', settings={'STRICT_PARSING': True}, locales=['en'])
None
>>> dateparser.parse('2017', settings={'STRICT_PARSING': True}, locales=['zh'])
2020-01-07 00:00:00 |
Yes, sure I'll check it |
|
It seems that For example, the result with The tests/test_parser.py One of the issues on We can see on master, the same test with locales=['en'] parses This PR implements a filter method that, when Another option to handle cases like this could be a new parameter to define the minimum date length when But yeah, by default I think probably it should keep parsing those 4 digits date. What do you think @noviluni ? |
Add check to only try to parse complete dates if the date string has at least 6 digits.
Fix cases when it's impossible to guess the date
Ex:
Date: 11117
Possible dates: 11/01/17 or 01/11/17 or 11/11/07
So I suggest a minimum length of 6 to parse complete dates.
Closes #356