mcabbott / mcabbott/AxisKeys.jl

Index eltypes unioned on empty `KeyedArray`

Open
#81 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
154
Forks
31
PR merge metrics
No merged PRs in 30d

Description

There seems to be a weird bug where the axiskey eltypes get unionized when converting a KeyedArray with an empty dimension to a table. Perhaps we should define a Tables.schema method for a KeyedArray to avoid this problem?

julia> ka = KeyedArray(rand(0, 3); x=1:0, y=[:a, :b, :c])
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   x ∈ 0-element UnitRange{Int64}
→   y ∈ 3-element Vector{Symbol}
And data, 0×3 Matrix{Float64}

julia> Tables.schema(DataFrame(ka))
Tables.Schema:
 :x      Union{Int64, Symbol}
 :y      Union{Int64, Symbol}
 :value  Float64
 
 julia> ka = KeyedArray(rand(0, 3, 2); x=1:0, y=[:a, :b, :c], z=["foo", "bar"])
3-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   x ∈ 0-element UnitRange{Int64}
→   y ∈ 3-element Vector{Symbol}
□   z ∈ 2-element Vector{String}
And data, 0×3×2 Array{Float64, 3}

julia> Tables.schema(DataFrame(ka))
Tables.Schema:
 :x      Union{Int64, String, Symbol}
 :y      Union{Int64, String, Symbol}
 :z      Union{Int64, String, Symbol}
 :value  Float64
 
 julia> eltype.(axiskeys(ka))
(Int64, Symbol, String)

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

Start by running the KeyedArray examples in the issue and inspect how KeyedArray values are converted to tables, including the Tables.schema interface. Check the axis key eltypes for empty dimensions and compare them with the schema produced by DataFrame(ka). Done means the schema preserves each axis key type instead of unioning unrelated key types.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.