diff --git a/NEWS.md b/NEWS.md index 232ce17..5097724 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/src/collect1.jl b/src/collect1.jl index be00534..399902c 100644 --- a/src/collect1.jl +++ b/src/collect1.jl @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index b81ae26..888e1ac 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)