mcabbott / mcabbott/AxisKeys.jl

indexed assignment does not work with dimension name specification

Open
#67 2 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

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

  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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.