JuliaArrays / JuliaArrays/StructArrays.jl

collect_structarray does not work with empty iterator

Open
#100 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
402
Forks
49
PR merge metrics
No merged PRs in 30d

Description

julia> StructVector(x for x in [] if false)
ERROR: UndefVarError: T not defined
Stacktrace:
 [1] buildfromschema(::Function, ::Core.TypeofBottom) at /home/takafumi/.julia/dev/StructArrays/src/lazy.jl:25
 [2] (::StructArrays.StructArrayInitializer{StructArrays.var"#41#43",typeof(StructArrays.default_array)})(::Type, ::Tuple{Int64}) at /home/takafumi/.julia/dev/StructArrays/src/collect.jl:13
 [3] #collect_empty_structarray#104 at /home/takafumi/.julia/dev/StructArrays/src/collect.jl:52 [inlined]
 [4] #collect_structarray#103 at /home/takafumi/.julia/dev/StructArrays/src/collect.jl:47 [inlined]
 [5] #collect_structarray#101 at /home/takafumi/.julia/dev/StructArrays/src/collect.jl:41 [inlined]
 [6] #StructArray#40 at /home/takafumi/.julia/dev/StructArrays/src/structarray.jl:81 [inlined]
 [7] StructArray at /home/takafumi/.julia/dev/StructArrays/src/structarray.jl:81 [inlined]
 [8] #StructVector#8 at /home/takafumi/.julia/dev/StructArrays/src/structarray.jl:49 [inlined]
 [9] StructArray{T,1,C,I} where I where C<:Union{Tuple, NamedTuple} where T(::Base.Generator{Base.Iterators.Filter{var"#128#130",Array{Any,1}},var"#127#129"}) at /home/takafumi/.julia/dev/StructArrays/src/structarray.jl:49

I think it makes sense to at least make the error message less cryptic.

If you want to make it return something, my preference is to return an array of Union{} element type. Related discussion in: https://github.com/JuliaData/TypedTables.jl/issues/55

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the empty-iterator case with StructVector(x for x in [] if false), then inspect src/collect.jl and src/lazy.jl at the stack-trace locations. Review the related TypedTables.jl discussion to determine whether the result should use Union{} or only provide a clearer error; done means the empty case has intentional, tested behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.