Skip to content

Commit

Permalink
implement deleteat (#102)
Browse files Browse the repository at this point in the history
* implement deleteat

* Update src/functions.jl

Co-authored-by: Glenn Moynihan <[email protected]>

* test for invalid state

* Update test/_functions.jl

* use wrapdims

Co-authored-by: Glenn Moynihan <[email protected]>
  • Loading branch information
mzgubic and glennmoy authored Feb 11, 2022
1 parent 69a040c commit a78ba3d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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.0"
version = "0.2.1"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand All @@ -27,7 +27,7 @@ FiniteDifferences = "0.12"
IntervalSets = "0.5.1"
InvertedIndices = "1.0"
LazyStack = "0.0.7, 0.0.8"
NamedDims = "0.2.45"
NamedDims = "0.2.46"
OffsetArrays = "0.10, 0.11, 1.0"
StatsBase = "0.32, 0.33"
Tables = "0.2, 1"
Expand Down
6 changes: 6 additions & 0 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,9 @@ LinearAlgebra.cholesky(A::Hermitian{T, <:KeyedArray{T}}; kwargs...) where {T} =
cholesky(parent(A); kwargs...)
LinearAlgebra.cholesky(A::KeyedMatrix; kwargs...) =
cholesky(keyless_unname(A); kwargs...)

function Base.deleteat!(v::KeyedVector, inds)
deleteat!(axiskeys(v, 1), inds)
deleteat!(v.data, inds)
return v
end
13 changes: 13 additions & 0 deletions test/_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ end
@test AxisKeys.hasnames(similar(M, 2,2,2)) == false

end
@testset "deleteat!" begin
kv = wrapdims([1, 2, 3, 4, 5, 6.0], a=[:a, :b, :c, :d, :e, :f])

@test kv == deleteat!(kv, 1) == KeyedArray([2, 3, 4, 5, 6.0], a=[:b, :c, :d, :e, :f])
@test kv == deleteat!(kv, 1:2) == KeyedArray([4, 5, 6.0], a=[:d, :e, :f])
@test kv == deleteat!(kv, (1, 3)) == KeyedArray([5.0], a=[:e])

# make sure array is not in an invalid state if the deleteat for indices fails
ka = wrapdims([4, 5, 6.0], a=1:3)
@test_throws MethodError deleteat!(ka, 2)
@test ka == KeyedArray([4, 5, 6.0], a=1:3)
end

@testset "equality" begin

data = parent(parent(M))
Expand Down

2 comments on commit a78ba3d

@mcabbott
Copy link
Owner

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/54462

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.1 -m "<description of version>" a78ba3d0ecc47d9345aeed4e773bf44056719d32
git push origin v0.2.1

Please sign in to comment.