JuliaArrays / JuliaArrays/StructArrays.jl
Handling nested structs
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 402
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
Hi Pietro. Great package!
Any thought about how to support nested structs? e.g.
julia> struct Point
x::Int
y::Int
end
julia> struct Foo
id::Int
name::String
pt::Point
end
julia> x = [Foo(i, "foo$i", Point(2i, 3i)) for i in 1:3]
3-element Array{Foo,1}:
Foo(1, "foo1", Point(2, 3))
Foo(2, "foo2", Point(4, 6))
Foo(3, "foo3", Point(6, 9))
I can do it like this:
julia> x2 = StructArray(
id = [f.id for f in x],
name = [f.name for f in x],
pt = StructArray(f.pt for f in x))
3-element StructArray(::Array{Int64,1}, ::Array{String,1}, StructArray(::Array{Int64,1}, ::Array{Int64,1})) with eltype NamedTuple{(:id, :name, :pt),Tuple{Int64,String,Point}}:
(id = 1, name = "foo1", pt = Point(2, 3))
(id = 2, name = "foo2", pt = Point(4, 6))
(id = 3, name = "foo3", pt = Point(6, 9))
It's a little bit unsatisfactory since I have to enumerate all non-struct fields (id and name in the above) manually...
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing StructArray constructor and how it handles struct-valued fields. Use the nested Point and Foo example in the issue to understand the desired behavior. Done means nested structs can be handled without manually enumerating the non-struct fields, with the intended API and behavior documented or tested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100