Skip to content

Commit

Permalink
Merge 6c594f1 into 9b91d54
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed May 26, 2021
2 parents 9b91d54 + 6c594f1 commit a9ab46e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Expand Up @@ -6,12 +6,14 @@ version = "0.4.3"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
RangeArrays = "b3c3ace0-ae52-54e7-9d0b-2c1406fd6b9d"

[compat]
IntervalSets = "0.1, 0.2, 0.3, 0.4, 0.5"
IterTools = "1"
RangeArrays = "0.3"
OffsetArrays = "1"
julia = "1"

[extras]
Expand Down
3 changes: 3 additions & 0 deletions src/AxisArrays.jl
Expand Up @@ -7,6 +7,7 @@ import Base.Iterators: repeated
using RangeArrays, IntervalSets
using IterTools
using Dates
using OffsetArrays

function axes end

Expand All @@ -23,4 +24,6 @@ include("sortedvector.jl")
include("categoricalvector.jl")
include("combine.jl")

include("offsetarrays.jl") # extend OffsetArrays

end
6 changes: 6 additions & 0 deletions src/offsetarrays.jl
@@ -0,0 +1,6 @@
if isdefined(OffsetArrays, :centered)
# Compat for OffsetArrays v1.9
# https://github.com/JuliaArrays/OffsetArrays.jl/pull/242
OffsetArrays.centered(ax::Axis{name}) where name = Axis{name}(OffsetArrays.centered(ax.val))
OffsetArrays.centered(a::AxisArray) = AxisArray(OffsetArrays.centered(a.data), OffsetArrays.centered.(AxisArrays.axes(a)))
end
22 changes: 22 additions & 0 deletions test/offsetarrays.jl
@@ -0,0 +1,22 @@
if isdefined(OffsetArrays, :centered)
# only test this if we're using OffsetArrays at least v1.9
@testset "centered" begin
check_range(r, f, l) = (@test first(r) == f; @test last(r) == l)
check_range_axes(r, f, l) = check_range(Base.axes(r)[1], f, l)

check_range(Base.axes(OffsetArrays.centered(1:3))[1], -1, 1)
a = AxisArray(rand(3, 3), Axis{:y}(0.1:0.1:0.3), Axis{:x}(1:3))

ca = OffsetArrays.centered(a)
axs = Base.axes(ca)
check_range(axs[1], -1, 1)
check_range(axs[2], -1, 1)
@test ca[OffsetArrays.center(ca)...] == a[OffsetArrays.center(a)...]

axs = AxisArrays.axes(ca)
check_range(axs[1].val, 0.1, 0.3)
check_range(axs[2].val, 1, 3)
check_range_axes(axs[1].val, -1, 1)
check_range_axes(axs[1].val, -1, 1)
end
end
5 changes: 5 additions & 0 deletions test/runtests.jl
Expand Up @@ -2,6 +2,7 @@ using AxisArrays
using Dates
using Test
using Random
using OffsetArrays
import IterTools

@testset "AxisArrays" begin
Expand Down Expand Up @@ -38,4 +39,8 @@ import IterTools
@testset "README" begin
include("readme.jl")
end

@testset "OffsetArrays" begin
include("offsetarrays.jl")
end
end

0 comments on commit a9ab46e

Please sign in to comment.