Skip to content

Commit

Permalink
Fix deprecations with nt.names and kw.data (#201)
Browse files Browse the repository at this point in the history
also fix a test-only depwarn using IntervalSets
  • Loading branch information
JeffFessler authored Jul 25, 2021
1 parent bf961cf commit 4e29472
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ function AxisArray(A::AbstractArray{T,N}, names::NTuple{N,Symbol}, steps::NTuple
end

# Alternative constructor, takes names as keywords:
AxisArray(A; kw...) = AxisArray(A, nt_to_axes(kw.data)...)
@generated nt_to_axes(nt::NamedTuple) =
Expr(:tuple, (:(Axis{$(QuoteNode(n))}(getfield(nt, $(QuoteNode(n))))) for n in nt.names)...)
AxisArray(A; kw...) = AxisArray(A, nt_to_axes(values(kw)))
@generated nt_to_axes(nt::NamedTuple{names}) where {names} =
Expr(:tuple, (:(Axis{$(QuoteNode(n))}(getfield(nt, $(QuoteNode(n))))) for n in names)...)

AxisArray(A::AxisArray) = A
AxisArray(A::AxisArray, ax::Vararg{Axis, N}) where N =
Expand Down
6 changes: 3 additions & 3 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ end

# Keyword indexing, reconstructs the Axis{}() objects
@propagate_inbounds Base.view(A::AxisArray; kw...) =
view(A, kw_to_axes(parent(A), kw.data)...)
view(A, kw_to_axes(parent(A), values(kw))...)
@propagate_inbounds Base.getindex(A::AxisArray; kw...) =
getindex(A, kw_to_axes(parent(A), kw.data)...)
getindex(A, kw_to_axes(parent(A), values(kw))...)
@propagate_inbounds Base.setindex!(A::AxisArray, val; kw...) =
setindex!(A, val, kw_to_axes(parent(A), kw.data)...)
setindex!(A, val, kw_to_axes(parent(A), values(kw))...)

function kw_to_axes(A::AbstractArray, nt::NamedTuple)
length(nt) == 0 && throw(BoundsError(A, ())) # Trivial case A[] lands here
Expand Down
4 changes: 2 additions & 2 deletions test/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ v = [1 .. 2, 3.0 .. 4.0]
@test 4 in 2.0 .. 6.0
@test 4 in 4.0 .. 4.0
@test 4 in 4.0 .. 5
@test (1..2) in (0.5 .. 2.5)
@test !((1..2) in (1.5 .. 2.5))
@test (1..2) (0.5 .. 2.5)
@test !((1..2) (1.5 .. 2.5))

@test maximum(1..2) === 2
@test minimum(1..2) === 1
Expand Down

0 comments on commit 4e29472

Please sign in to comment.