From d8d864c38334f7f7520ec69609ad33ddddb2d00a Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Fri, 27 May 2022 08:11:16 +0300 Subject: [PATCH] support view of a single element by names/keys --- src/names.jl | 8 ++++---- test/_basic.jl | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/names.jl b/src/names.jl index e533409..76bfc16 100644 --- a/src/names.jl +++ b/src/names.jl @@ -94,14 +94,14 @@ end @inline @propagate_inbounds (A::NdaKa)(args...) = getkey(A, args...) -@inline @propagate_inbounds (A::KaNda)(;kw...) = getkey(A; kw...) -@inline @propagate_inbounds (A::NdaKa)(;kw...) = getkey(A; kw...) +@inline @propagate_inbounds (A::KaNda)(c=nothing; kw...) = getkey(A, c; kw...) +@inline @propagate_inbounds (A::NdaKa)(c=nothing; kw...) = getkey(A, c; kw...) -@inline @propagate_inbounds function getkey(A; kw...) +@inline @propagate_inbounds function getkey(A, c::Union{Nothing, Colon}; kw...) list = dimnames(A) issubset(keys(kw), list) || error("some keywords not in list of names!") args = map(s -> Base.sym_in(s, keys(kw)) ? getfield(values(kw), s) : Colon(), list) - A(args...) + isnothing(c) ? A(args...) : A(args..., c) end # Constructors, including pirate method (A; kw...) diff --git a/test/_basic.jl b/test/_basic.jl index 822375c..212be38 100644 --- a/test/_basic.jl +++ b/test/_basic.jl @@ -170,6 +170,10 @@ end @test_throws Exception N(obs=55) # ideally ArgumentError @test_throws Exception N(obs='z') # ideally BoundsError + + Nc = copy(N) + Nc(obs='a', iter=20, :) .= 1000 + @test Nc(obs='a', iter=20) == 1000 end @testset "named_axiskeys" begin