File tree Expand file tree Collapse file tree 3 files changed +22
-22
lines changed Expand file tree Collapse file tree 3 files changed +22
-22
lines changed Original file line number Diff line number Diff line change 11module AxisKeys
22
33include (" struct.jl" )
4- export KeyedArray, axiskeys, named_axiskeys
4+ export KeyedArray, axiskeys
55
66include (" lookup.jl" )
77
88include (" names.jl" )
9- export NamedDimsArray, dimnames
9+ export NamedDimsArray, dimnames, named_axiskeys
1010
1111include (" wrap.jl" )
1212export wrapdims
Original file line number Diff line number Diff 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)
132132end
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
Original file line number Diff line number Diff line change @@ -50,26 +50,6 @@ axiskeys(x::KeyedVector) = tuple(getindex(getfield(x, :keys)))
5050axiskeys (x:: KeyedArray , d:: Int ) = d<= ndims (x) ? getindex (axiskeys (x), d) : OneTo (1 )
5151axiskeys (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-
7353Base. IndexStyle (A:: KeyedArray ) = IndexStyle (parent (A))
7454
7555Base. eachindex (A:: KeyedArray ) = eachindex (parent (A))
You can’t perform that action at this time.
0 commit comments