Skip to content

Commit 83a275c

Browse files
committed
Add axisindexes docs
1 parent a901a3a commit 83a275c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/indexing.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,28 @@ end
144144
### Indexing along values of the axes ###
145145

146146
# Default axes indexing throws an error
147+
"""
148+
axisindexes(ax::Axis, axis_idx) -> array_idx
149+
axisindexes(::Type{<:AxisTrait}, axis_values, axis_idx) -> array_idx
150+
151+
Translate an index into an axis into an index into the underlying array.
152+
Users can add additional indexing behaviours for custom axes or custom indices by adding
153+
methods to this function.
154+
155+
## Examples
156+
157+
Add a method for indexing into an `Axis{name, SortedSet}`:
158+
159+
```julia
160+
AxisArrays.axisindexes(::Type{Categorical}, ax::SortedSet, idx::AbstractVector) = findin(collect(ax), idx)
161+
```
162+
163+
Add a method for indexing into a `Categorical` axis with a `SortedSet`:
164+
165+
```julia
166+
AxisArrays.axisindexes(::Type{Categorical}, ax::AbstractVector, idx::SortedSet) = findin(ax, idx)
167+
```
168+
"""
147169
axisindexes(ax, idx) = axisindexes(axistrait(ax.val), ax.val, idx)
148170
axisindexes(::Type{Unsupported}, ax, idx) = error("elementwise indexing is not supported for axes of type $(typeof(ax))")
149171
axisindexes(t, ax, idx) = error("cannot index $(typeof(ax)) with $(typeof(idx)); expected $(eltype(ax)) axis value or Integer index")

0 commit comments

Comments
 (0)