Skip to content

Commit

Permalink
Merge pull request #63 from xiaodaigh/bugfix/datetime-w-missing
Browse files Browse the repository at this point in the history
fixed date with missing
  • Loading branch information
xiaodaigh authored Apr 15, 2021
2 parents 9e8c6f6 + 06a970b commit 46a3aa1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 0.4.1
fixed date with missing issues

## 0.4
Returning a JDFFile type that is Tables.jl compatible
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JDF"
uuid = "babc3d20-cd49-4f60-a736-a8f9c08892d3"
authors = ["Dai ZJ <zhuojia.dai@gmail.com>"]
version = "0.4.0"
version = "0.4.1"

[deps]
Blosc = "a74b3585-a348-5f62-a45c-50e91977d574"
Expand Down
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)

2 comments on commit 46a3aa1

@xiaodaigh
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/34337

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.1 -m "<description of version>" 46a3aa1ec097b4b0d635cadda6fa9b5547640ce8
git push origin v0.4.1

Please sign in to comment.