6060# Entry from NamedTuple, Dict, or kwargs
6161ComponentArray {T} (nt:: NamedTuple ) where T = ComponentArray (make_carray_args (T, nt)... )
6262ComponentArray {T} (:: NamedTuple{(), Tuple{}} ) where T = ComponentArray (T[], (FlatAxis (),))
63- ComponentArray (nt:: NamedTuple ) = ComponentArray (make_carray_args (nt)... )
63+ ComponentArray (nt:: Union{ NamedTuple, AbstractDict} ) = ComponentArray (make_carray_args (nt)... )
6464ComponentArray (:: NamedTuple{(), Tuple{}} ) = ComponentArray (Any[], (FlatAxis (),))
65- ComponentArray (d:: AbstractDict ) = ComponentArray (NamedTuple {Tuple(keys(d))} (values (d)))
6665ComponentArray {T} (;kwargs... ) where T = ComponentArray {T} ((;kwargs... ))
6766ComponentArray (;kwargs... ) = ComponentArray ((;kwargs... ))
6867
@@ -138,17 +137,22 @@ make_carray_args(::NamedTuple{(), Tuple{}}) = (Any[], FlatAxis())
138137make_carray_args (:: Type{T} , :: NamedTuple{(), Tuple{}} ) where {T} = (T[], FlatAxis ())
139138function make_carray_args (nt)
140139 data, ax = make_carray_args (Vector, nt)
141- data = length (data)== 1 ? [data[1 ]] : reduce (vcat , data)
140+ data = length (data)== 1 ? [data[1 ]] : map (identity , data)
142141 return (data, ax)
143142end
144143make_carray_args (:: Type{T} , nt) where {T} = make_carray_args (Vector{T}, nt)
145144function make_carray_args (A:: Type{<:AbstractArray} , nt)
146- data, idx = make_idx ([], nt, 0 )
145+ T = recursive_eltype (nt)
146+ init = _isbitstype (T) ? T[] : []
147+ data, idx = make_idx (init, nt, 0 )
147148 return (A (data), Axis (idx))
148149end
149150
151+ _isbitstype (:: Type{<:Union{T, Nothing, Missing}} ) where {T} = isbitstype (T)
152+ _isbitstype (T) = isbitstype (T)
153+
150154# Builds up data vector and returns appropriate AbstractAxis type for each input type
151- function make_idx (data, nt:: NamedTuple , last_val)
155+ function make_idx (data, nt:: Union{ NamedTuple, AbstractDict} , last_val)
152156 len = recursive_length (nt)
153157 kvs = []
154158 lv = 0
@@ -325,4 +329,4 @@ julia> sum(prod(ca[k]) for k in valkeys(ca))
325329 k = Val .(keys (idxmap))
326330 return :($ k)
327331end
328- valkeys (ca:: ComponentVector ) = valkeys (getaxes (ca)[1 ])
332+ valkeys (ca:: ComponentVector ) = valkeys (getaxes (ca)[1 ])
0 commit comments