Skip to content

Commit 8b0ab10

Browse files
committed
Change API for Missing vs DataValue materialization
1 parent a34a88d commit 8b0ab10

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/TableTraitsUtils.jl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,26 @@ end
7676
end
7777
end
7878

79-
function _default_array_factory(t,rows)
80-
if isa(t, TypeVar)
81-
return Array{Any}(undef, rows)
82-
else
83-
return Array{t}(undef, rows)
84-
end
85-
end
86-
87-
function create_columns_from_iterabletable(source; sel_cols=:all, array_factory=_default_array_factory)
79+
function create_columns_from_iterabletable(source; sel_cols=:all, na_representation=:datavalue)
8880
iter = getiterator(source)
8981

9082
T = eltype(iter)
9183
if !(T<:NamedTuple)
9284
error("Can only collect a NamedTuple iterator.")
9385
end
9486

87+
array_factory = if na_representation==:datavalue
88+
(t,rows) -> Array{t}(undef, rows)
89+
elseif na_representation==:missing
90+
(t,rows) -> begin
91+
if t <: DataValue
92+
return Array{Union{eltype(t),Missing}}(undef, rows)
93+
else
94+
return Array{t}(undef, rows)
95+
end
96+
end
97+
end
98+
9599
column_types = collect(T.parameters[2].parameters)
96100
column_names = collect(T.parameters[1])
97101

0 commit comments

Comments
 (0)