From 2aa614299c9ad8222ab54ff0ea93bdcd956919f1 Mon Sep 17 00:00:00 2001 From: Dai ZJ Date: Thu, 15 Apr 2021 12:05:29 +1000 Subject: [PATCH 1/2] fixed date with missing --- src/loadjdf.jl | 8 ++------ src/savejdf.jl | 4 +++- src/type-writer-loader/Missing.jl | 5 +++-- test/test-date-w-missing.jl | 8 ++++++++ 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 test/test-date-w-missing.jl 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) From 06a970bc498c19d60340a674c5bbe1ccb799a981 Mon Sep 17 00:00:00 2001 From: Dai ZJ Date: Thu, 15 Apr 2021 12:07:06 +1000 Subject: [PATCH 2/2] minor --- NEWS.md | 2 ++ Project.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index cb8450a..cba1977 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +## 0.4.1 +fixed date with missing issues ## 0.4 Returning a JDFFile type that is Tables.jl compatible diff --git a/Project.toml b/Project.toml index fcd8d50..3c9ee10 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JDF" uuid = "babc3d20-cd49-4f60-a736-a8f9c08892d3" authors = ["Dai ZJ "] -version = "0.4.0" +version = "0.4.1" [deps] Blosc = "a74b3585-a348-5f62-a45c-50e91977d574"