diff --git a/src/names.jl b/src/names.jl index 4bf4204..5817910 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 59db1ca..0c37913 100644 --- a/test/_basic.jl +++ b/test/_basic.jl @@ -170,7 +170,7 @@ end @test_throws Exception N(obs=55) # ideally ArgumentError @test_throws Exception N(obs='z') # ideally BoundsError - + new_obs = [:x, :y, :z] new_iter = 1:4 @@ -180,6 +180,10 @@ end @test axiskeys(rekey(N, 2 => 1:4)) == (['a', 'b', 'c'], 1:4) # Rekey with dimname => axiskey pair @test axiskeys(rekey(N, :iter => 1:4)) == (['a', 'b', 'c'], 1:4) + + Nc = copy(N) + Nc(obs='a', iter=20, :) .= 1000 + @test Nc(obs='a', iter=20) == 1000 end @testset "named_axiskeys" begin