Skip to content

Commit 47800b8

Browse files
committed
move named_axiskeys to names.jl
1 parent 7b0ef68 commit 47800b8

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

src/AxisKeys.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module AxisKeys
22

33
include("struct.jl")
4-
export KeyedArray, axiskeys, named_axiskeys
4+
export KeyedArray, axiskeys
55

66
include("lookup.jl")
77

88
include("names.jl")
9-
export NamedDimsArray, dimnames
9+
export NamedDimsArray, dimnames, named_axiskeys
1010

1111
include("wrap.jl")
1212
export wrapdims

src/names.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,23 @@ function NamedDims.NamedDimsArray(A::AbstractArray; kw...)
130130
map(x -> axes(x, 1), R) == axes(A) || throw(ArgumentError("axes of keys must match axes of array"))
131131
NamedDimsArray(KeyedArray(A, R), L)
132132
end
133+
134+
"""
135+
named_axiskeys(arr)::NamedTuple
136+
137+
Return the [`axiskeys`](@ref) along with their names.
138+
If there are duplicate names or unnamed axes, an error is thrown.
139+
140+
```jldoctest
141+
julia> using AxisKeys
142+
143+
julia> arr = KeyedArray([1 2], x=[1], y=[2,3]);
144+
145+
julia> named_axiskeys(arr)
146+
(x = [1], y = [2, 3])
147+
```
148+
"""
149+
function named_axiskeys(arr)::NamedTuple
150+
NT = NamedTuple{dimnames(arr)}
151+
return NT(axiskeys(arr))
152+
end

src/struct.jl

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,6 @@ axiskeys(x::KeyedVector) = tuple(getindex(getfield(x, :keys)))
5050
axiskeys(x::KeyedArray, d::Int) = d<=ndims(x) ? getindex(axiskeys(x), d) : OneTo(1)
5151
axiskeys(x::KeyedVector, d::Int) = d==1 ? getindex(getfield(x, :keys)) : OneTo(1)
5252

53-
"""
54-
named_axiskeys(arr)::NamedTuple
55-
56-
Return the [`axiskeys`](@ref) along with their names.
57-
If there are duplicate names or unnamed axes, an error is thrown.
58-
59-
```jldoctest
60-
julia> using AxisKeys
61-
62-
julia> arr = KeyedArray([1 2], x=[1], y=[2,3]);
63-
64-
julia> named_axiskeys(arr)
65-
(x = [1], y = [2, 3])
66-
```
67-
"""
68-
function named_axiskeys(arr)::NamedTuple
69-
NT = NamedTuple{dimnames(arr)}
70-
return NT(axiskeys(arr))
71-
end
72-
7353
Base.IndexStyle(A::KeyedArray) = IndexStyle(parent(A))
7454

7555
Base.eachindex(A::KeyedArray) = eachindex(parent(A))

0 commit comments

Comments
 (0)