mcabbott / mcabbott/AxisKeys.jl

`push!` can leave the original array in a broken state

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

This seems fine:

A = KeyedArray(rand(Int8, 2); index=["a", "b"])
push!(A, 5)

1-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓   index ∈ 3-element Vector{Any}
And data, 3-element Vector{Int8}:
  ("a")   106
  ("b")  -121
 (3)        5

but:

A

ArgumentError: lengths of key vectors must match size of array (and their axes too)

Stacktrace:
  [1] construction_check
    @ ~/.julia/packages/AxisKeys/pm7Fb/src/struct.jl:30 [inlined]
  [2] KeyedArray
    @ ~/.julia/packages/AxisKeys/pm7Fb/src/struct.jl:17 [inlined]
  [3] KeyedArray
    @ ~/.julia/packages/AxisKeys/pm7Fb/src/struct.jl:20 [inlined]
  [4] unname
    @ ~/.julia/packages/AxisKeys/pm7Fb/src/names.jl:29 [inlined]
  [5] _summary(io::IOContext{IOBuffer}, x::KeyedArray{Int8, 1, NamedDimsArray{(:index,), Int8, 1, Vector{Int8}}, Base.RefValue{Vector{String}}})
    @ AxisKeys ~/.julia/packages/AxisKeys/pm7Fb/src/show.jl:16
  [6] summary
    @ ~/.julia/packages/AxisKeys/pm7Fb/src/show.jl:2 [inlined]
  [7] show(io::IOContext{IOBuffer}, #unused#::MIME{Symbol("text/plain")}, X::KeyedArray{Int8, 1, NamedDimsArray{(:index,), Int8, 1, Vector{Int8}}, Base.RefValue{Vector{String}}})
    @ Base ./arrayshow.jl:337
  [8] limitstringmime(mime::MIME{Symbol("text/plain")}, x::KeyedArray{Int8, 1, NamedDimsArray{(:index,), Int8, 1, Vector{Int8}}, Base.RefValue{Vector{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 reproducing the example with push! and then inspect the referenced paths in src/struct.jl, src/names.jl, and src/show.jl. Trace why the original KeyedArray no longer satisfies its key-length check after push!. Done means the original array remains valid and can be displayed without the ArgumentError.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.