Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support empty components #162

Merged
merged 11 commits into from
Aug 6, 2022
Merged
Prev Previous commit
Next Next commit
treat dict like nt
  • Loading branch information
YichengDWu committed Jul 31, 2022
commit 2f1b6f58fcc4fe82c14a854b665bb4474ef4569e
8 changes: 4 additions & 4 deletions src/componentarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ end
# Entry from NamedTuple, Dict, or kwargs
ComponentArray{T}(nt::NamedTuple) where T = ComponentArray(make_carray_args(T, nt)...)
ComponentArray{T}(::NamedTuple{(), Tuple{}}) where T = ComponentArray(T[], (FlatAxis(),))
ComponentArray(nt::NamedTuple) = ComponentArray(make_carray_args(nt)...)
ComponentArray(nt::Union{NamedTuple, AbstractDict}) = ComponentArray(make_carray_args(nt)...)
ComponentArray(::NamedTuple{(), Tuple{}}) = ComponentArray(Any[], (FlatAxis(),))
ComponentArray(d::AbstractDict) = ComponentArray(NamedTuple{Tuple(keys(d))}(values(d)))
#ComponentArray(d::AbstractDict) = ComponentArray(NamedTuple{Tuple(keys(d))}(values(d)))
ComponentArray{T}(;kwargs...) where T = ComponentArray{T}((;kwargs...))
ComponentArray(;kwargs...) = ComponentArray((;kwargs...))

Expand Down Expand Up @@ -138,7 +138,7 @@ make_carray_args(::NamedTuple{(), Tuple{}}) = (Any[], FlatAxis())
make_carray_args(::Type{T}, ::NamedTuple{(), Tuple{}}) where {T} = (T[], FlatAxis())
function make_carray_args(nt)
data, ax = make_carray_args(Vector, nt)
data = length(data)==1 ? [data[1]] : data
data = length(data)==1 ? [data[1]] : map(identity, data)
return (data, ax)
end
make_carray_args(::Type{T}, nt) where {T} = make_carray_args(Vector{T}, nt)
Expand All @@ -153,7 +153,7 @@ _isprimitivetype(::Type{<:Union{T, Nothing, Missing}}) where {T} = isprimitivety
_isprimitivetype(T) = isprimitivetype(T)

# Builds up data vector and returns appropriate AbstractAxis type for each input type
function make_idx(data, nt::NamedTuple, last_val)
function make_idx(data, nt::Union{NamedTuple, Dict}, last_val)
len = recursive_length(nt)
kvs = []
lv = 0
Expand Down