diff --git a/src/loadjdf.jl b/src/loadjdf.jl index 99d91fc..4d3eef5 100644 --- a/src/loadjdf.jl +++ b/src/loadjdf.jl @@ -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 @@ -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 diff --git a/src/savejdf.jl b/src/savejdf.jl index c8a3622..b2e92cd 100644 --- a/src/savejdf.jl +++ b/src/savejdf.jl @@ -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 @@ -25,6 +25,8 @@ some_elm(::Type{T}) where {T} = begin end end +some_elm(::Type{Date}) = Date(0) + """ JDF.save(outdir, table) diff --git a/src/type-writer-loader/Missing.jl b/src/type-writer-loader/Missing.jl index 4cf8114..419120a 100644 --- a/src/type-writer-loader/Missing.jl +++ b/src/type-writer-loader/Missing.jl @@ -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)) @@ -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 diff --git a/test/test-date-w-missing.jl b/test/test-date-w-missing.jl new file mode 100644 index 0000000..ae92cf1 --- /dev/null +++ b/test/test-date-w-missing.jl @@ -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)