Skip to content

Commit

Permalink
Large performance improvement when parsing custom date formats (#471)
Browse files Browse the repository at this point in the history
* Large performance improvement when parsing custom date formats

* fixed compatibility with Julia 1.0 for not supporting isnothing

close #472
  • Loading branch information
jbaron authored Nov 5, 2020
1 parent e609cf9 commit f9416ae
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/readwrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ function readtimearray(source; delim::Char = ',', meta = nothing,
inoempty = findall(s -> length(s) > 2, cfile[:, 1])
cfile = cfile[inoempty, :]

# create a DataFormat instance to improve performance
df = isempty(format) ? nothing : DateFormat(format)

time = cfile[1:end, 1]
if length(time[1]) < 11
# assuming Date not DateTime
tstamps = isempty(format) ?
tstamps = df === nothing ?
Date[Date(t) for t in time] :
Date[Date(t, format) for t in time]
Date[Date(t, df) for t in time]
else
tstamps = isempty(format) ?
tstamps = df === nothing ?
DateTime[DateTime(t) for t in time] :
DateTime[DateTime(t, format) for t in time]
DateTime[DateTime(t, df) for t in time]
end

vals = insertNaN(cfile[1:end, 2:end])
Expand Down

0 comments on commit f9416ae

Please sign in to comment.