Skip to content

Commit a950315

Browse files
committed
Use Compat to:
- Fix error with 0.7 on Base.Dates - deprecation warning breaks use of Dates.AbstractTime - Fix warnings with use of Range instead of AbstractRange - Fix deprecated use of (x...) to (x...,)
1 parent 9994724 commit a950315

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ julia 0.6
22
IntervalSets 0.1
33
IterTools
44
RangeArrays
5+
Compat 0.33.0

src/AxisArrays.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ using Base: tail
66
import Base.Iterators: repeated
77
using RangeArrays, IntervalSets
88
using IterTools
9+
using Compat
10+
using Compat.Dates
11+
using Compat: AbstractRange
912

1013
export AxisArray, Axis, axisnames, axisvalues, axisdim, axes, atindex, atvalue, collapse
1114

src/core.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ axes(A::AbstractArray, dim::Int) = default_axes(A)[dim]
506506
507507
Returns the axis parameters for an AxisArray.
508508
"""
509-
axisparams(::AxisArray{T,N,D,Ax}) where {T,N,D,Ax} = (Ax.parameters...)
510-
axisparams(::Type{AxisArray{T,N,D,Ax}}) where {T,N,D,Ax} = (Ax.parameters...)
509+
axisparams(::AxisArray{T,N,D,Ax}) where {T,N,D,Ax} = (Ax.parameters...,)
510+
axisparams(::Type{AxisArray{T,N,D,Ax}}) where {T,N,D,Ax} = (Ax.parameters...,)
511511

512512
### Axis traits ###
513513
abstract type AxisTrait end

src/indexing.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,31 +252,32 @@ axisindexes(::Type{Dimensional}, ax::AbstractVector, idx::ClosedInterval) = sear
252252
# time, we want `A[interval] == vec(A[interval + [0]])`. To make these
253253
# computations as similar as possible, we use a phony range of the form
254254
# `step(ax):step(ax):step(ax)` in order to search for the interval.
255-
phony_range(r::Range) = step(r):step(r):step(r)
255+
phony_range(r::AbstractRange) = step(r):step(r):step(r)
256256
phony_range(r::AbstractUnitRange) = step(r):step(r)
257257
phony_range(r::StepRangeLen) = StepRangeLen(r.step, r.step, 1)
258-
function relativewindow(r::Range, x::ClosedInterval)
258+
function relativewindow(r::AbstractRange, x::ClosedInterval)
259259
pr = phony_range(r)
260260
idxs = Extrapolated.searchsorted(pr, x)
261261
vals = Extrapolated.getindex(pr, idxs)
262262
return (idxs, vals)
263263
end
264264

265265
axisindexes(::Type{Dimensional}, ax::AbstractVector, idx::RepeatedInterval) = error("repeated intervals might select a varying number of elements for non-range axes; use a repeated Range of indices instead")
266-
function axisindexes(::Type{Dimensional}, ax::Range, idx::RepeatedInterval)
266+
function axisindexes(::Type{Dimensional}, ax::AbstractRange, idx::RepeatedInterval)
267267
idxs, vals = relativewindow(ax, idx.window)
268268
offsets = [Extrapolated.searchsortednearest(ax, offset) for offset in idx.offsets]
269269
AxisArray(RepeatedRangeMatrix(idxs, offsets), Axis{:sub}(vals), Axis{:rep}(Extrapolated.getindex(ax, offsets)))
270270
end
271271

272272
# We also have special datatypes to represent intervals about indices
273273
axisindexes(::Type{Dimensional}, ax::AbstractVector, idx::IntervalAtIndex) = searchsorted(ax, idx.window + ax[idx.index])
274-
function axisindexes(::Type{Dimensional}, ax::Range, idx::IntervalAtIndex)
274+
function axisindexes(::Type{Dimensional}, ax::AbstractRange, idx::IntervalAtIndex)
275275
idxs, vals = relativewindow(ax, idx.window)
276276
AxisArray(idxs + idx.index, Axis{:sub}(vals))
277277
end
278278
axisindexes(::Type{Dimensional}, ax::AbstractVector, idx::RepeatedIntervalAtIndexes) = error("repeated intervals might select a varying number of elements for non-range axes; use a repeated Range of indices instead")
279-
function axisindexes(::Type{Dimensional}, ax::Range, idx::RepeatedIntervalAtIndexes)
279+
function axisindexes(::Type{Dimensional}, ax::AbstractRange,
280+
idx::RepeatedIntervalAtIndexes)
280281
idxs, vals = relativewindow(ax, idx.window)
281282
AxisArray(RepeatedRangeMatrix(idxs, idx.indexes), Axis{:sub}(vals), Axis{:rep}(ax[idx.indexes]))
282283
end

src/search.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function searchsortednearest(vec::AbstractVector, x)
1616
return idx
1717
end
1818
# Base only specializes searching ranges by Numbers; so optimize for Intervals
19-
function Base.searchsorted(a::Range, I::ClosedInterval)
19+
function Base.searchsorted(a::AbstractRange, I::ClosedInterval)
2020
searchsortedfirst(a, I.left):searchsortedlast(a, I.right)
2121
end
2222

@@ -27,8 +27,9 @@ sufficient since it can be turned off by `--check-bounds=yes`.
2727
"""
2828
module Extrapolated
2929
using ..ClosedInterval
30+
using Compat: AbstractRange
3031

31-
function searchsortednearest(vec::Range, x)
32+
function searchsortednearest(vec::AbstractRange, x)
3233
idx = searchsortedfirst(vec, x) # Returns the first idx | vec[idx] >= x
3334
if (getindex(vec, idx) - x) > (x - getindex(vec, idx-1))
3435
idx -= 1 # The previous element is closer
@@ -37,25 +38,25 @@ function searchsortednearest(vec::Range, x)
3738
end
3839

3940
"""
40-
searchsorted(a::Range, I::ClosedInterval)
41+
searchsorted(a::AbstractRange, I::ClosedInterval)
4142
4243
Return the indices of the range that fall within an interval without checking
4344
bounds, possibly extrapolating outside the range if needed.
4445
"""
45-
function searchsorted(a::Range, I::ClosedInterval)
46+
function searchsorted(a::AbstractRange, I::ClosedInterval)
4647
searchsortedfirst(a, I.left):searchsortedlast(a, I.right)
4748
end
4849

4950
# When running with `--check-bounds=yes` (like on Travis), the bounds-check isn't elided
50-
@inline function getindex(v::Range{T}, i::Integer) where T
51+
@inline function getindex(v::AbstractRange{T}, i::Integer) where T
5152
convert(T, first(v) + (i-1)*step(v))
5253
end
53-
@inline function getindex(r::Range, s::Range{<:Integer})
54+
@inline function getindex(r::AbstractRange, s::AbstractRange{<:Integer})
5455
f = first(r)
5556
st = oftype(f, f + (first(s)-1)*step(r))
5657
range(st, step(r)*step(s), length(s))
5758
end
58-
getindex(r::Range, I::Array) = [getindex(r, i) for i in I]
59+
getindex(r::AbstractRange, I::Array) = [getindex(r, i) for i in I]
5960
@inline getindex(r::StepRangeLen, i::Integer) = Base.unsafe_getindex(r, i)
6061
@inline function getindex(r::StepRangeLen, s::AbstractUnitRange)
6162
soffset = 1 + (r.offset - first(s))
@@ -68,29 +69,29 @@ getindex(r::Range, I::Array) = [getindex(r, i) for i in I]
6869
end
6970
end
7071

71-
function searchsortedlast(a::Range, x)
72+
function searchsortedlast(a::AbstractRange, x)
7273
step(a) == 0 && throw(ArgumentError("ranges with a zero step are unsupported"))
7374
n = round(Integer,(x-first(a))/step(a))+1
7475
isless(x, getindex(a, n)) ? n-1 : n
7576
end
76-
function searchsortedfirst(a::Range, x)
77+
function searchsortedfirst(a::AbstractRange, x)
7778
step(a) == 0 && throw(ArgumentError("ranges with a zero step are unsupported"))
7879
n = round(Integer,(x-first(a))/step(a))+1
7980
isless(getindex(a, n), x) ? n+1 : n
8081
end
81-
function searchsortedlast(a::Range{<:Integer}, x)
82+
function searchsortedlast(a::AbstractRange{<:Integer}, x)
8283
step(a) == 0 && throw(ArgumentError("ranges with a zero step are unsupported"))
8384
fld(floor(Integer,x)-first(a),step(a))+1
8485
end
85-
function searchsortedfirst(a::Range{<:Integer}, x)
86+
function searchsortedfirst(a::AbstractRange{<:Integer}, x)
8687
step(a) == 0 && throw(ArgumentError("ranges with a zero step are unsupported"))
8788
-fld(floor(Integer,-x)+first(a),step(a))+1
8889
end
89-
function searchsortedfirst(a::Range{<:Integer}, x::Unsigned)
90+
function searchsortedfirst(a::AbstractRange{<:Integer}, x::Unsigned)
9091
step(a) == 0 && throw(ArgumentError("ranges with a zero step are unsupported"))
9192
-fld(first(a)-signed(x),step(a))+1
9293
end
93-
function searchsortedlast(a::Range{<:Integer}, x::Unsigned)
94+
function searchsortedlast(a::AbstractRange{<:Integer}, x::Unsigned)
9495
step(a) == 0 && throw(ArgumentError("ranges with a zero step are unsupported"))
9596
fld(signed(x)-first(a),step(a))+1
9697
end

0 commit comments

Comments
 (0)