You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Split a separate "no-spaces" parser setting off of the current "absolute-time" one #751
Currently, including the absolute-time entry into the PARSERS array in settings actually results in trying to parse the datestring by two distinct parsers under the hood.
This issue proposes to split off the two parsers into their own separate entries of PARSERS, so the user can tune their usage and precedence to her liking.
Example use-case
EDIT: Seem this use-case is already discussed in a separate issue: #356
One specific use-case that can be brought to light is when parsing dates in strict mode and encountering strings with only a year in them:
Obviously, the chance of someone writing "2016" with the intent to mean "Jan 06, 2020" is pretty low. Disabling the "no spaces" parser is one way to circumvent such behavior. More granular settings for the particular parser might be needed if one needs some of its other functionalities (feel free to file a separate issue for that).
Currently, a workaround for disabling the "no spaces" parser can be monkey-patching dateparser.parser.no_space_parser_eligibile to always return False, but as we know, monkey-patching is generally not the best thing in the world. (Credits to @JohannesBuchner for proposing a similar workaround for a different issue in this comment)
Naming ambiguities
The actual setting name for the "no-spaces" parser needs further consideration, as this parser does not correspond exactly to the cases of strings without any (white)spaces. Formally, looking at the current no_space_parser_eligibile implementation this parser handles:
strings with only digits (no other symbols whatsoever - spaces, dots, colons, etc)
strings for which the first non-digit symbol is : (this is rather strange, as "11.05:2020" will not be handled, but the nonsense string of "11:05.2020" is parsed to datetime.datetime(2005, 1, 1, 0, 0))
The result is that a proper datestring like "11.05.2020", which does not have spaces, will not be handled by the current "no spaces" parser.
I think that you are right, we should separate those parsers to avoid those situations.
I didn't have time to check the code carefully to see how feasible is this, but when having a moment I will give it a try and I will also check the weird behavior you described in the "Naming ambiguities" section.
Of course, if you want to open a PR in the meanwhile don't hesitate to do it 😄
After checking the v1.0.0 milestone you've added, I've actually discovered that the "example use-case" described here is already discussed in another issue: #356. I will update the info above with that.
Nevertheless, having the ability to separately use the 2 parses should still have other valid uses-cases and is not directly tied to the year parsing issue.
Thanks @noviluni! I've glanced over the PR and added some questions/comments.
As far as the naming goes - not sure there's something short enough to describes the parser - probably something like digits-and-colon-only-parser (which is still not entirely true, as the parser allows other non-digit symbols, as long as the first one is a colon, but looking at the example above it probably ignores these parts - need to dig deeper in the patterns to verify that).
Activity
noviluni commentedon Jul 23, 2020
Hi @skyuchukov-bp , thank you for the proposal!
I think that you are right, we should separate those parsers to avoid those situations.
I didn't have time to check the code carefully to see how feasible is this, but when having a moment I will give it a try and I will also check the weird behavior you described in the "Naming ambiguities" section.
Of course, if you want to open a PR in the meanwhile don't hesitate to do it 😄
Thanks again for raising this up!
related issue: #713
related PR: #715
skyuchukov-bp commentedon Jul 23, 2020
Thanks for the fast reply @noviluni.
After checking the v1.0.0 milestone you've added, I've actually discovered that the "example use-case" described here is already discussed in another issue: #356. I will update the info above with that.
Nevertheless, having the ability to separately use the 2 parses should still have other valid uses-cases and is not directly tied to the year parsing issue.
cfculhane commentedon Aug 11, 2020
Thanks for this, the STRICT_PARSER=True parsing of "2017" -> datetime.datetime(2017, 8, 11, 0, 0) is driving me crazy :)
noviluni commentedon Sep 16, 2020
Hi @skyuchukov-bp , I added a PR separating the "no_spaces" parser: #786
If you have the chance, it would be really nice if you check it.
From now, you could do:
And it will return
None.@cfculhane you could also check if this works for you :)
Thanks in advance!
noviluni commentedon Sep 16, 2020
Ah @skyuchukov-bp !
And if you have any idea for the naming ambiguities it will be welcomed!
skyuchukov-bp commentedon Sep 17, 2020
Thanks @noviluni! I've glanced over the PR and added some questions/comments.
As far as the naming goes - not sure there's something short enough to describes the parser - probably something like
digits-and-colon-only-parser(which is still not entirely true, as the parser allows other non-digit symbols, as long as the first one is a colon, but looking at the example above it probably ignores these parts - need to dig deeper in the patterns to verify that).