Skip to content

Commit 3a3a919

Browse files
authored
Merge pull request #138 from mjp98/mjp/empty
Add method `Base.emtpy!(::KeyedVector)`
2 parents a96b5b5 + e65d5fe commit 3a3a919

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AxisKeys"
22
uuid = "94b1ba4f-4ee9-5380-92f1-94cde586c3c5"
33
license = "MIT"
4-
version = "0.2.10"
4+
version = "0.2.11"
55

66
[deps]
77
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/functions.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,4 +441,9 @@ function Base.filter!(f, a::KeyedVector)
441441
deleteat!(a, j:lastindex(a))
442442
return a
443443
end
444-
444+
445+
function Base.empty!(v::KeyedVector)
446+
empty!(axiskeys(v, 1))
447+
empty!(v.data)
448+
return v
449+
end

test/_functions.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ end
148148

149149
@test axiskeys(filter(isodd, V2),1) isa Vector{Int}
150150
@test dimnames(filter(isodd, V2)) == (:v,)
151-
151+
152152
V4 = wrapdims(rand(1:99, 10), collect(2:11))
153153
V4c = copy(V4)
154154
@test filter!(isodd, V4c) === V4c == filter(isodd, V4)
@@ -288,6 +288,17 @@ end
288288
@test ka == KeyedArray([4, 5, 6.0], a=1:3)
289289
end
290290

291+
@testset "empty!" begin
292+
kv = wrapdims([1, 2, 3, 4, 5, 6.0], a=[:a, :b, :c, :d, :e, :f])
293+
@test kv == empty!(kv)
294+
@test isempty(kv)
295+
296+
# make sure array is not in an invalid state if the emtpy for indices fails
297+
ka = wrapdims([4, 5, 6.0], a=1:3)
298+
@test_throws MethodError empty!(ka)
299+
@test ka == KeyedArray([4, 5, 6.0], a=1:3)
300+
end
301+
291302
@testset "equality" begin
292303

293304
data = parent(parent(M))

0 commit comments

Comments
 (0)