mcabbott / mcabbott/AxisKeys.jl

Cannot create KeyedArray from some tables

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

Docs for wrapdims say

wrapdims(table, value, names...; default=undef, sort=false, force=false)
Construct KeyedArray(NamedDimsArray(A,names),keys) from a table matching
the Tables.jl API.
(It must support both Tables.columns and Tables.rows.)
The contents of the array is taken from the column value::Symbol of the table.
Each symbol in names specifies a column whose unique entries
become the keys along a dimenension of the array.

It works with the most basic column-table:

julia> wrapdims((a=[1, 2], b=[2, 1]), :a, :b)
1-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   b ∈ 2-element Vector{Int64}
And data, 2-element Vector{Int64}:
 (2)  1
 (1)  2

but not with a rowtable - an exception gets thrown:

julia> wrapdims([(a=1, b=2), (a=2, b=1)], :a, :b)
ERROR: ArgumentError: wrong number of names, got (:a, :b) with ndims(A) == 1
Stacktrace:
 [1] check_names(A::Vector{NamedTuple{(:a, :b), Tuple{Int64, Int64}}}, names::Tuple{Symbol, Symbol})
   @ AxisKeys ~/.julia/packages/AxisKeys/KCixh/src/wrap.jl:105
 [2] wrapdims(A::Vector{NamedTuple{(:a, :b), Tuple{Int64, Int64}}}, n::Symbol, names::Symbol)
   @ AxisKeys ~/.julia/packages/AxisKeys/KCixh/src/wrap.jl:87

Looks like a wrong method gets dispatched: https://github.com/mcabbott/AxisKeys.jl/blob/master/src/wrap.jl#L87 instead of https://github.com/mcabbott/AxisKeys.jl/blob/master/src/tables.jl#L213.

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 failure with the row-table example in the issue, then inspect src/wrap.jl around line 87 and src/tables.jl around line 213. Compare the dispatched methods for column tables and row tables. Done means the row-table call reaches the Tables.jl-aware method and constructs the expected KeyedArray without the wrong-number-of-names error.

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
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.