Skip to content

Commit

Permalink
fixed date with missing
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodaigh committed Apr 15, 2021
1 parent 9e8c6f6 commit 2aa6142
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/loadjdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ version is used.
load(indir; cols = Symbol[], verbose = false) = begin
# starting from DataFrames.jl 0.21 the colnames are strings
cols = string.(cols)
metadatas = open(joinpath(indir, "metadata.jls")) do io
deserialize(io)
end
metadatas = jdfmetadata(indir)

# TODO simplify this this is duplicated in load_columns
if length(cols) == 0
Expand All @@ -34,9 +32,7 @@ sload(jdf::JDFFile; args...) = sload(path(jdf); args...)
# load the data from file with a schema
function sload(indir; cols = Symbol[], verbose = false)
cols = string.(cols)
metadatas = open(joinpath(indir, "metadata.jls")) do io
deserialize(io)
end
metadatas = jdfmetadata(indir)

# TODO simplify this
if length(cols) == 0
Expand Down
4 changes: 3 additions & 1 deletion src/savejdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Tables
Some arbitrary element of type `T`
"""
some_elm(::Type{T}) where {T} = begin
function some_elm(::Type{T}) where {T}
try
return zero(T)
catch
Expand All @@ -25,6 +25,8 @@ some_elm(::Type{T}) where {T} = begin
end
end

some_elm(::Type{Date}) = Date(0)

"""
JDF.save(outdir, table)
Expand Down
5 changes: 3 additions & 2 deletions src/type-writer-loader/Missing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ some_elm(::Type{Missing}) = missing


# the dispatch for Union{T, Missing}
# 1. comporess the missing
# 1. compress the missing
# 2. and also load the missing
compress_then_write(b::Vector{Union{T,Missing}}, io) where {T} = begin
S = nonmissingtype(eltype(b))
Expand All @@ -24,7 +24,8 @@ compress_then_write(b::Vector{Union{T,Missing}}, io) where {T} = begin
end

# just write it out as missing
compress_then_write(b::Vector{Missing}, io) =
# notice how io is not needed since nothing need to be written
compress_then_write(b::Vector{Missing}, _) =
(len = 0, type = Missing, orig_len = length(b))

column_loader!(buffer, ::Type{Union{Missing,T}}, io, metadata) where {T} = begin
Expand Down
8 changes: 8 additions & 0 deletions test/test-date-w-missing.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Guard aginst github #62
using JDF
using Dates
col = [Date(1999,1,1), missing]
df = (d = col, a = [1, missing])
JDF.save("plsdel-date-w-missing.jdf", df)
DataFrame(JDF.load("plsdel-date-w-missing.jdf"))
rm("plsdel-date-w-missing.jdf", recursive=true)

0 comments on commit 2aa6142

Please sign in to comment.