|
63 | 63 | # getproperty: it's useful to say for `(i,t) in enumerate(A.time)` etc. |
64 | 64 | # This will make saying ".data" slow (by 30ns), fixed in NamedDims.jl#78 |
65 | 65 |
|
66 | | -Base.propertynames(A::NdaKa{L}, private=false) where {L} = |
| 66 | +Base.propertynames(A::NdaKa{L}, private::Bool=false) where {L} = |
67 | 67 | private ? (L..., fieldnames(typeof(A))...) : L |
68 | | -Base.propertynames(A::KaNda{L}, private=false) where {L} = |
| 68 | +Base.propertynames(A::KaNda{L}, private::Bool=false) where {L} = |
69 | 69 | private ? (L..., fieldnames(typeof(A))...) : L |
70 | 70 |
|
71 | 71 | Base.getproperty(A::NdaKa{L}, s::Symbol) where {L} = |
@@ -130,3 +130,23 @@ function NamedDims.NamedDimsArray(A::AbstractArray; kw...) |
130 | 130 | map(x -> axes(x, 1), R) == axes(A) || throw(ArgumentError("axes of keys must match axes of array")) |
131 | 131 | NamedDimsArray(KeyedArray(A, R), L) |
132 | 132 | 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 |
0 commit comments