mcabbott / mcabbott/AxisKeys.jl

`wrapdims` doesn't work when axis eltype is `UnitRange`

Open
#168 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

It works when the eltype is a tuple of ints, but not when it's a range.

julia> wrapdims(DataFrame(a=[(1,2), (3,4)], b=[10, 20], c=[100, 200]), :c, :a, :b)
2-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   a ∈ 2-element Vector{Tuple{Int64, Int64}}
→   b ∈ 2-element Vector{Int64}
And data, 2×2 Matrix{Int64}:
            (10)  (20)
   (1, 2)    100     0
   (3, 4)      0   200

julia> wrapdims(DataFrame(a=[(1:2), (3:4)], b=[10, 20], c=[100, 200]), :c, :a, :b)
ERROR: ArgumentError: could not find key 1 in vector UnitRange{Int64}[1:2, 3:4]
Stacktrace:
  [1] findindex
    @ ~/.julia/packages/AxisKeys/sYP4R/src/lookup.jl:80 [inlined]
  [2] (::AxisKeys.var"#15#16"{Vector{UnitRange{Int64}}})(x::Int64)
    @ AxisKeys ./none:0
  [3] iterate
    @ ./generator.jl:48 [inlined]
  [4] collect
    @ ./array.jl:791 [inlined]
  [5] findindex
    @ ~/.julia/packages/AxisKeys/sYP4R/src/lookup.jl:86 [inlined]
  [6] map
    @ ./tuple.jl:383 [inlined]
  [7] populate_function_barrier!(A::KeyedArray{…}, value_column::Vector{…}, axis_key_columns::Tuple{…}, mask::BitMatrix, force::Bool)
    @ AxisKeys ~/.julia/packages/AxisKeys/sYP4R/src/tables.jl:153
  [8] populate!(A::KeyedArray{Int64, 2, NamedDimsArray{…}, Tuple{…}}, table::DataFrame, value::Symbol; force::Bool)
    @ AxisKeys ~/.julia/packages/AxisKeys/sYP4R/src/tables.jl:144
  [9] populate!(A::KeyedArray{Int64, 2, NamedDimsArray{…}, Tuple{…}}, table::DataFrame, value::Symbol)
    @ AxisKeys ~/.julia/packages/AxisKeys/sYP4R/src/tables.jl:137
 [10] _wrap_table(::Type{…}, ::typeof(identity), ::DataFrame, ::Symbol, ::Symbol, ::Vararg{…}; default::UndefInitializer, sort::Bool, kwargs::@Kwargs{})
    @ AxisKeys ~/.julia/packages/AxisKeys/sYP4R/src/tables.jl:277
 [11] _wrap_table(::Type, ::Function, ::DataFrame, ::Symbol, ::Symbol, ::Vararg{Symbol})
    @ AxisKeys ~/.julia/packages/AxisKeys/sYP4R/src/tables.jl:253
 [12] wrapdims(::DataFrame, ::Symbol, ::Symbol, ::Vararg{Symbol}; kw::@Kwargs{})
    @ AxisKeys ~/.julia/packages/AxisKeys/sYP4R/src/tables.jl:232
 [13] wrapdims(::DataFrame, ::Symbol, ::Symbol, ::Symbol, ::Vararg{Symbol})
    @ AxisKeys ~/.julia/packages/AxisKeys/sYP4R/src/tables.jl:230
 [14] top-level scope

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 Julia example, then start in src/tables.jl at populate_function_barrier! and follow its calls into src/lookup.jl at findindex. Check how tuple-valued axis keys are handled versus Vector{UnitRange{Int64}}. Done means wrapdims accepts the range-valued axis column and produces the same key-to-value placement without the reported 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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.