-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Custom parser for dates. #18000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom parser for dates. #18000
Conversation
cc: @omus |
Something I would like to see regarding date parsing/formatting would be to parameterize the DateFormat type with the format being used. Something similar to |
Since this change is about performance there should probably be some performance tests added to https://github.com/JuliaCI/BaseBenchmarks.jl regarding parsing dates. |
Yes, it would be nice to have a way to hack in parsers for various common formats as they come up. Either dispatch or just if/else statements that return |
I should have pointed to the discussion on the open issue #15888. There is |
Isn't the parser tag for julia parser stuff? |
Which is why I want, eventually, the ability to manually write parsers for specific formats. I'm thinking of something like:
Yes. |
I also want this. My only issue with the if/else approach is that it won't be extensible by other packages. I'm specifically thinking about TimeZones.jl and the |
58d9ff9
to
75a76df
Compare
I've added an |
@@ -258,14 +250,15 @@ backslash. The date "1995y01m" would have the format "y\\ym\\m". | |||
DateTime(dt::AbstractString,format::AbstractString;locale::AbstractString="english") = DateTime(dt,DateFormat(format,locale)) | |||
|
|||
""" | |||
DateTime(dt::AbstractString, df::DateFormat) -> DateTime | |||
DateTime(dt::AbstractString, df::AbstractDateFormat) -> DateTime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change needs to be made in the rst docs too
75a76df
to
1c858ac
Compare
Updated the docs, any other comments? |
|
||
Construct a `DateTime` by parsing the `dt` date string following the pattern given in | ||
the [`DateFormat`](:func:`Dates.DateFormat`) object. Similar to | ||
`DateTime(::AbstractString, ::AbstractString)` but more efficient when repeatedly parsing | ||
similarly formatted date strings with a pre-created `DateFormat` object. | ||
""" | ||
DateTime(dt::AbstractString,df::DateFormat=ISODateTimeFormat) = DateTime(parse(dt,df)...) | ||
DateTime(dt::AbstractString,df::DateFormat) = DateTime(parse(dt,df)...) | ||
DateTime(str::AbstractString) = DateTime(str,ISODateTimeFormat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be dt::AbstractString
to match the above signature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems reasonable, updated.
ede295b
to
00a120c
Compare
Should we merge this now, as we figure out improvements going forward? |
Let's make sure CI still passes, there have been a month of changes on master since it last ran here. edit: I think the osx failure edit2: win64 appveyor failure is just #16555, also nothing new |
Bump? |
On an unrelated note, I just noticed that we are missing |
We should put in an explicit check for better-supported format strings like |
(A benchmark of this was added to BaseBenchmarks.) |
00a120c
to
309d57f
Compare
@nanosoldier |
Your benchmark job has completed - no performance regressions were detected. A full report can be found here. cc @jrevels |
Looks like no date parse benchmark was run? |
I think new benchmarks need to be manually deployed, it's not automatic from merging PR's |
The tuning process is running now, I'll retrigger benchmarks here once it finishes. EDIT: Tuning process failed, so it'll be a little while longer. There was a bug in a recently added benchmark, I fixed it in JuliaCI/BaseBenchmarks.jl/pull/35. Once tests pass and I merge the fix, I'll restart the tuning process... |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
I've done some iterating on this proposal and have some code which doesn't need |
@omus Any update, or should we just merge this? |
@JeffBezanson thanks for the bump. I'll try to get out my proposal tonight. If I can't we can merge this first. |
this is superseded by / contained in #19545, right? |
@tkelman correct |
This replaces the default date parser with a custom-coded version. It is approximately 50x faster on the following snippet: