Skip to content

Commit

Permalink
Merge pull request #138 from mjp98/mjp/empty
Browse files Browse the repository at this point in the history
Add method `Base.emtpy!(::KeyedVector)`
  • Loading branch information
oxinabox authored Feb 3, 2023
2 parents a96b5b5 + e65d5fe commit 3a3a919
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 6 additions & 1 deletion src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion test/_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

2 comments on commit 3a3a919

@oxinabox
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/76941

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.11 -m "<description of version>" 3a3a919f021478c4b93f33ed0d5d6e65c31bdc82
git push origin v0.2.11

Please sign in to comment.