Skip to content

Commit

Permalink
Fix a DataValue{Any} corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff committed Jul 9, 2019
1 parent 7e4ac55 commit 62e807e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TableTraitsUtils.jl v1.0.0 Release Notes
* Drop julia 0.7 support
* Move to Project.toml
* Fix a bug in materializing DataValue{Any} columns with Missing option

# TableTraitsUtils.jl v0.4.0 Release Notes
* Use DataValueArray for missing columns in collection stuff
Expand Down
12 changes: 10 additions & 2 deletions src/collect1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ end
push_exprs = Expr(:block)
for col_idx in 1:length(fieldnames(T))
if fieldtype(TYPES, col_idx)!==Nothing
ex = :( dest[$col_idx][i] = el[$col_idx] )
if fieldtype(TYPES, col_idx) == Array{Any,1} && fieldtype(T, col_idx) == DataValue{Any}
ex = :( dest[$col_idx][i] = get(el[$col_idx], missing) )
else
ex = :( dest[$col_idx][i] = el[$col_idx] )
end
push!(push_exprs.args, ex)
end
end
Expand All @@ -84,7 +88,11 @@ end
push_exprs = Expr(:block)
for col_idx in 1:length(fieldnames(T))
if fieldtype(TYPES, col_idx)!==Nothing
ex = :( push!(dest[$col_idx], el[$col_idx]) )
if fieldtype(TYPES, col_idx) == Array{Any,1} && fieldtype(T, col_idx) == DataValue{Any}
ex = :( push!(dest[$col_idx], get(el[$col_idx], missing)) )
else
ex = :( push!(dest[$col_idx], el[$col_idx]) )
end
push!(push_exprs.args, ex)
end
end
Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ columns23, names23 = TableTraitsUtils.create_columns_from_iterabletable(it, sel_
@test names == names2 == names3
@test names[2:3] == names23

@test isequal(create_columns_from_iterabletable([(a=DataValue{Any}(), b=DataValue{Int}())], na_representation=:missing),
([Any[missing], Union{Missing,Int}[missing]], [:a, :b])
)

@test create_columns_from_iterabletable([(a=DataValue{Any}(), b=DataValue{Int}())], na_representation=:datavalue) ==
([DataValue{Any}[NA], DataValue{Int}[NA]], [:a, :b])

it2 = TestSourceWithoutLength()

columns4, names4 = TableTraitsUtils.create_columns_from_iterabletable(it2)
Expand Down

0 comments on commit 62e807e

Please sign in to comment.