JuliaArrays / JuliaArrays/StructArrays.jl

Feature Request: Singleton type support

Open
#335 1 comment 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

Currently:

julia> StructArray([nothing, nothing])
ERROR: ArgumentError: only eltypes with fields are supported
Stacktrace:
 [1] (StructVector{Nothing, @NamedTuple{}})(c::@NamedTuple{})
   @ StructArrays ~/.julia/packages/StructArrays/bgm9N/src/structarray.jl:17
 [2] (StructArray{Nothing})(c::@NamedTuple{})
   @ StructArrays ~/.julia/packages/StructArrays/bgm9N/src/structarray.jl:94
 [3] buildfromschema(initializer::StructArrays.var"#28#29"{…}, ::Type{…}, ::Type{…})
   @ StructArrays ~/.julia/packages/StructArrays/bgm9N/src/utils.jl:48
 [4] buildfromschema(initializer::StructArrays.var"#28#29"{typeof(StructArrays.alwaysfalse), Vector{Nothing}}, ::Type{Nothing})
   @ StructArrays ~/.julia/packages/StructArrays/bgm9N/src/utils.jl:35
 [5] similar_structarray(v::Vector{Nothing}, ::Type{Nothing}; unwrap::typeof(StructArrays.alwaysfalse))
   @ StructArrays ~/.julia/packages/StructArrays/bgm9N/src/structarray.jl:182
 [6] StructArray(v::Vector{Nothing}; unwrap::typeof(StructArrays.alwaysfalse))
   @ StructArrays ~/.julia/packages/StructArrays/bgm9N/src/structarray.jl:260
 [7] StructArray(v::Vector{Nothing})
   @ StructArrays ~/.julia/packages/StructArrays/bgm9N/src/structarray.jl:259
 [8] top-level scope
   @ REPL[43]:1
Some type information was truncated. Use `show(err)` to see complete types.

This feels like an unnecessary limitation. I have an application where I want to be able to store collections of StructArrays filled with concrete types that may or may not be singleton types. It's inconvenient for me to have to fall back on regular vectors for singleton structs.

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 singleton-type case from the issue in the REPL, then read src/structarray.jl and src/utils.jl around the reported constructors and buildfromschema calls. Done means StructArray([nothing, nothing]) and collections containing singleton and non-singleton concrete types work without falling back to regular vectors.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.