From b9f3e37f237254a6f302ecc135cca75a6c5ecddb Mon Sep 17 00:00:00 2001 From: Matthew Priddin Date: Fri, 3 Feb 2023 17:31:57 +0000 Subject: [PATCH 1/3] Define `empty!(::KeyedVector)` --- src/functions.jl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/functions.jl b/src/functions.jl index e65a97b..3d152a7 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -441,4 +441,9 @@ function Base.filter!(f, a::KeyedVector) deleteat!(a, j:lastindex(a)) return a end - + +function Base.empty!(v::KeyedVector) + empty!(axiskeys(v, 1)) + empty!(v.data) + return v +end From 75f5f2d69fdd676f602e2724d1cb37aa4699b697 Mon Sep 17 00:00:00 2001 From: Matthew Priddin Date: Fri, 3 Feb 2023 17:32:05 +0000 Subject: [PATCH 2/3] Add tests --- test/_functions.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/_functions.jl b/test/_functions.jl index 40548b9..83410bc 100644 --- a/test/_functions.jl +++ b/test/_functions.jl @@ -148,7 +148,7 @@ end @test axiskeys(filter(isodd, V2),1) isa Vector{Int} @test dimnames(filter(isodd, V2)) == (:v,) - + V4 = wrapdims(rand(1:99, 10), collect(2:11)) V4c = copy(V4) @test filter!(isodd, V4c) === V4c == filter(isodd, V4) @@ -288,6 +288,17 @@ end @test ka == KeyedArray([4, 5, 6.0], a=1:3) end +@testset "empty!" begin + kv = wrapdims([1, 2, 3, 4, 5, 6.0], a=[:a, :b, :c, :d, :e, :f]) + @test kv == empty!(kv) + @test isempty(kv) + + # make sure array is not in an invalid state if the emtpy for indices fails + ka = wrapdims([4, 5, 6.0], a=1:3) + @test_throws MethodError empty!(ka) + @test ka == KeyedArray([4, 5, 6.0], a=1:3) +end + @testset "equality" begin data = parent(parent(M)) From e65d5feaf8f9de50d1177c76acff8d7162e260a6 Mon Sep 17 00:00:00 2001 From: Matthew Priddin Date: Fri, 3 Feb 2023 17:32:15 +0000 Subject: [PATCH 3/3] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3015728..f00e2e5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AxisKeys" uuid = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5" license = "MIT" -version = "0.2.10" +version = "0.2.11" [deps] AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"