Skip to content

Commit

Permalink
Dropped method to rekey and rename at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
rofinn committed Oct 25, 2022
1 parent ab95d13 commit cf7315a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
14 changes: 2 additions & 12 deletions src/names.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,9 @@ end
rekey(A, (1:10, [:a, :b]))
rekey(A, 2 => [:a, :b])
rekey(A, :y => [:a, :b])
rekey(A, :y => q => [:a, :b])
Rekey a KeyedArray via `Tuple`s, `dim => newkey`. If `A` also has named dimensions then you
can also pass `dimname => newkey`, or even `oldname => newname => newkey` to both `rename`
and `rekey` the specified dimension.
Rekey a KeyedArray via `Tuple`s or `Pair`s, `dim => newkey`. If `A` also has named
dimensions then you can also pass `dimname => newkey`.
"""
rekey(A::Union{KeyedArray, NdaKa}, k2::Tuple) = KeyedArray(keyless(A), k2)
function rekey(A::Union{KeyedArray, NdaKa}, k2::Pair{<:Integer, <:AbstractVector}...)
Expand All @@ -199,11 +197,3 @@ function rekey(A::Union{KaNda, NdaKa}, k2::Pair{Symbol, <:AbstractVector}...)
pairs = map(p -> NamedDims.dim(A, p[1]) => p[2], k2)
return rekey(A, pairs...)
end

function rekey(A::Union{KaNda, NdaKa}, k2::Pair{Symbol, <:Pair}...)
# Extract rekey pairs from k2
rekey_pairs = last.(k2)
# Extract the current dimname and desired dimname into pairs
rename_pairs = Pair.(first.(k2), first.(rekey_pairs))
return rekey(rename(A, rename_pairs...), rekey_pairs...)
end
2 changes: 0 additions & 2 deletions test/_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ 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)
# Rekey and rename
@test named_axiskeys(rekey(N, :obs => :label => [:x, :y, :z])) == (label=[:x, :y, :z], iter=10:10:40)
end

@testset "named_axiskeys" begin
Expand Down

0 comments on commit cf7315a

Please sign in to comment.