Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add range interface methods to Axis #176

Merged
merged 1 commit into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ Base.IteratorEltype(::Type{<:Axis}) = Base.HasEltype()
Base.iterate(::Type{T}) where {T<:Axis} = (T, nothing)
Base.iterate(::Type{T}, ::Any) where {T<:Axis} = nothing

Base.first(A::Axis) = first(A.val)
Base.last(A::Axis) = last(A.val)
Base.step(A::Axis{name,<:AbstractRange}) where {name} = step(A.val)

"""
An AxisArray is an AbstractArray that wraps another AbstractArray and
adds axis names and values to each array dimension. AxisArrays can be indexed
Expand Down
3 changes: 3 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ T = A[AxisArrays.Axis{:x}]
@test length(Axis{:col}(-1:2)) === 4
@test AxisArrays.axisname(Axis{:foo}(1:2)) == :foo
@test AxisArrays.axisname(Axis{:foo}) == :foo
@test first(Axis{:row}(1:3)) == 1
@test step(Axis{:row}(1:3)) == 1
@test last(Axis{:row}(1:3)) == 3

# Test Timetype axis construction
dt, vals = DateTime(2010, 1, 2, 3, 40), randn(5,2)
Expand Down