Skip to content

Commit 1b828cb

Browse files
authored
Merge pull request #12 from queryverse/fix-datavalue-any-case
Fix a DataValue{Any} corner case
2 parents 7e4ac55 + 62e807e commit 1b828cb

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# TableTraitsUtils.jl v1.0.0 Release Notes
22
* Drop julia 0.7 support
33
* Move to Project.toml
4+
* Fix a bug in materializing DataValue{Any} columns with Missing option
45

56
# TableTraitsUtils.jl v0.4.0 Release Notes
67
* Use DataValueArray for missing columns in collection stuff

src/collect1.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ end
7272
push_exprs = Expr(:block)
7373
for col_idx in 1:length(fieldnames(T))
7474
if fieldtype(TYPES, col_idx)!==Nothing
75-
ex = :( dest[$col_idx][i] = el[$col_idx] )
75+
if fieldtype(TYPES, col_idx) == Array{Any,1} && fieldtype(T, col_idx) == DataValue{Any}
76+
ex = :( dest[$col_idx][i] = get(el[$col_idx], missing) )
77+
else
78+
ex = :( dest[$col_idx][i] = el[$col_idx] )
79+
end
7680
push!(push_exprs.args, ex)
7781
end
7882
end
@@ -84,7 +88,11 @@ end
8488
push_exprs = Expr(:block)
8589
for col_idx in 1:length(fieldnames(T))
8690
if fieldtype(TYPES, col_idx)!==Nothing
87-
ex = :( push!(dest[$col_idx], el[$col_idx]) )
91+
if fieldtype(TYPES, col_idx) == Array{Any,1} && fieldtype(T, col_idx) == DataValue{Any}
92+
ex = :( push!(dest[$col_idx], get(el[$col_idx], missing)) )
93+
else
94+
ex = :( push!(dest[$col_idx], el[$col_idx]) )
95+
end
8896
push!(push_exprs.args, ex)
8997
end
9098
end

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ columns23, names23 = TableTraitsUtils.create_columns_from_iterabletable(it, sel_
5050
@test names == names2 == names3
5151
@test names[2:3] == names23
5252

53+
@test isequal(create_columns_from_iterabletable([(a=DataValue{Any}(), b=DataValue{Int}())], na_representation=:missing),
54+
([Any[missing], Union{Missing,Int}[missing]], [:a, :b])
55+
)
56+
57+
@test create_columns_from_iterabletable([(a=DataValue{Any}(), b=DataValue{Int}())], na_representation=:datavalue) ==
58+
([DataValue{Any}[NA], DataValue{Int}[NA]], [:a, :b])
59+
5360
it2 = TestSourceWithoutLength()
5461

5562
columns4, names4 = TableTraitsUtils.create_columns_from_iterabletable(it2)

0 commit comments

Comments
 (0)