mcabbott / mcabbott/AxisKeys.jl
indexed assignment does not work with dimension name specification
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 154
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
Indexing by dimension names does not seem to work for LHS assignments:
julia> K = wrapdims(rand(2,2), x=1:2, y=1:2);
julia> K[x=1] .= 0
ERROR: MethodError: no method matching dotview(::KeyedArray{Float64,2,NamedDimsArray{(:x, :y),Float64,2,Array{Float64,2}},Tuple{UnitRange{Int64},UnitRange{Int64}}}; x=1)
Closest candidates are:
dotview(::KeyedArray, ::Any...) at /home/takbal/.julia/packages/AxisKeys/G3Okw/src/struct.jl:137 got unsupported keyword argument "x"
dotview(::Any...) at broadcast.jl:1160 got unsupported keyword argument "x"
dotview(::BitArray, ::BitArray) at broadcast.jl:1130 got unsupported keyword argument "x"
...
Stacktrace:
[1] top-level scope at REPL[182]:1
It works for NamedDims though:
julia> parent(K)[x=1] .= 0
2-element NamedDimsArray(view(::Array{Float64,2}, 1, :), (:y,)):
↓ y 0.0
0.0
Looks like the reason is that the Base.dotview() specialization does not pass keyword arguments upwards.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/struct.jl:137, where the KeyedArray Base.dotview specialization is reported to reject keyword arguments, and compare it with the working parent(K) NamedDims example. Reproduce K[x=1] .= 0 in Julia, then verify that dimension-name indexing works for the assignment without the reported MethodError.
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