From 9b8e6ea818d3a9a6eb25a45b0fe4be2a9e18e438 Mon Sep 17 00:00:00 2001 From: "femtocleaner[bot]" Date: Fri, 11 Aug 2017 21:11:26 +0000 Subject: [PATCH] Fix deprecations --- src/IndexedTables.jl | 12 ++++++------ src/columns.jl | 26 +++++++++++++------------- src/indexing.jl | 22 +++++++++++----------- src/join.jl | 10 +++++----- src/utils.jl | 28 ++++++++++++++-------------- 5 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/IndexedTables.jl b/src/IndexedTables.jl index 0bf0a7c7..e6b65bc9 100644 --- a/src/IndexedTables.jl +++ b/src/IndexedTables.jl @@ -17,7 +17,7 @@ const DimName = Union{Int,Symbol} include("utils.jl") include("columns.jl") -immutable IndexedTable{T, D<:Tuple, C<:Columns, V<:AbstractVector} +struct IndexedTable{T, D<:Tuple, C<:Columns, V<:AbstractVector} index::C data::V @@ -41,7 +41,7 @@ Keyword arguments: * `presorted::Bool`: If true, the indices are assumed to already be sorted and no sorting is done. * `copy::Bool`: If true, the storage for the new array will not be shared with the passed indices and data. If false (the default), the passed arrays will be copied only if necessary for sorting. The only way to guarantee sharing of data is to pass `presorted=true`. """ -function IndexedTable{T,C<:Columns}(I::C, d::AbstractVector{T}; agg=nothing, presorted=false, copy=false) +function IndexedTable(I::C, d::AbstractVector{T}; agg=nothing, presorted=false, copy=false) where {T,C<:Columns} length(I) == length(d) || error("index and data must have the same number of elements") if !presorted && !issorted(I) @@ -94,7 +94,7 @@ end _convert(::Type{<:Tuple}, tup::Tuple) = tup _convert{T<:NamedTuple}(::Type{T}, tup::Tuple) = T(tup...) -convertkey{V,K,I}(t::IndexedTable{V,K,I}, tup::Tuple) = _convert(eltype(I), tup) +convertkey(t::IndexedTable{V,K,I}, tup::Tuple) where {V,K,I} = _convert(eltype(I), tup) ndims(t::IndexedTable) = length(t.index.columns) length(t::IndexedTable) = (flush!(t);length(t.index)) @@ -309,7 +309,7 @@ if isless(Base.VERSION, v"0.5.0-") writemime(io::IO, m::MIME"text/plain", t::IndexedTable) = show(io, t) end -function show{T,D<:Tuple}(io::IO, t::IndexedTable{T,D}) +function show(io::IO, t::IndexedTable{T,D}) where {T,D<:Tuple} flush!(t) n = length(t) n == 0 && (return print(io, "empty table $D => $T")) @@ -356,7 +356,7 @@ function show{T,D<:Tuple}(io::IO, t::IndexedTable{T,D}) end end -@compat abstract type SerializedIndexedTable end +abstract type SerializedIndexedTable end function serialize(s::AbstractSerializer, x::IndexedTable) flush!(x) @@ -389,7 +389,7 @@ function map(f, x::IndexedTable) end # lift projection on arrays of structs -map{T,D<:Tuple,C<:Tup,V<:Columns}(p::Proj, x::IndexedTable{T,D,C,V}) = +map(p::Proj, x::IndexedTable{T,D,C,V}) where {T,D<:Tuple,C<:Tup,V<:Columns} = IndexedTable(x.index, p(x.data.columns), presorted=true) (p::Proj)(x::IndexedTable) = map(p, x) diff --git a/src/columns.jl b/src/columns.jl index 1adbd1a7..b045bb1e 100644 --- a/src/columns.jl +++ b/src/columns.jl @@ -8,10 +8,10 @@ import Base: export Columns -immutable Columns{D<:Tup, C<:Tup} <: AbstractVector{D} +struct Columns{D<:Tup, C<:Tup} <: AbstractVector{D} columns::C - @compat function (::Type{Columns{D,C}}){D<:Tup,C<:Tup}(c) + function Columns{D,C}(c) where {D<:Tup,C<:Tup} length(c) > 0 || error("must have at least one column") n = length(c[1]) for i = 2:length(c) @@ -39,24 +39,24 @@ eltype{D,C}(::Type{Columns{D,C}}) = D length(c::Columns) = length(c.columns[1]) ndims(c::Columns) = 1 size(c::Columns) = (length(c),) -@compat Base.IndexStyle(::Type{<:Columns}) = IndexLinear() -summary{D<:Tuple}(c::Columns{D}) = "Columns{$D}" +Base.IndexStyle(::Type{<:Columns}) = IndexLinear() +summary(c::Columns{D}) where {D<:Tuple} = "Columns{$D}" empty!(c::Columns) = (foreach(empty!, c.columns); c) -similar{D,C}(c::Columns{D,C}) = Columns{D,C}(map(similar, c.columns)) -similar{D,C}(c::Columns{D,C}, n::Integer) = Columns{D,C}(map(a->similar(a,n), c.columns)) +similar(c::Columns{D,C}) where {D,C} = Columns{D,C}(map(similar, c.columns)) +similar(c::Columns{D,C}, n::Integer) where {D,C} = Columns{D,C}(map(a->similar(a,n), c.columns)) function Base.similar{T<:Columns}(::Type{T}, n::Int)::T T_cols = T.parameters[2] f = T_cols <: Tuple ? tuple : T_cols T(f(map(t->similar(t, n), T.parameters[2].parameters)...)) end -copy{D,C}(c::Columns{D,C}) = Columns{D,C}(map(copy, c.columns)) +copy(c::Columns{D,C}) where {D,C} = Columns{D,C}(map(copy, c.columns)) -getindex{D<:Tuple}(c::Columns{D}, i::Integer) = ith_all(i, c.columns) -getindex{D<:NamedTuple}(c::Columns{D}, i::Integer) = D(ith_all(i, c.columns)...) +getindex(c::Columns{D}, i::Integer) where {D<:Tuple} = ith_all(i, c.columns) +getindex(c::Columns{D}, i::Integer) where {D<:NamedTuple} = D(ith_all(i, c.columns)...) -getindex{D,C}(c::Columns{D,C}, p::AbstractVector) = Columns{D,C}(map(c->c[p], c.columns)) +getindex(c::Columns{D,C}, p::AbstractVector) where {D,C} = Columns{D,C}(map(c->c[p], c.columns)) @inline setindex!(I::Columns, r::Tup, i::Integer) = (foreach((c,v)->(c[i]=v), I.columns, r); I) @@ -130,8 +130,8 @@ sort(c::Columns) = c[sortperm(c)] map(p::ProjFn, c::Columns) = Columns(p(c.columns)) map(p::Proj, c::Columns) = p(c.columns) -vcat{D<:Tup,C<:Tuple}(c::Columns{D,C}, cs::Columns{D,C}...) = Columns{D,C}((map(vcat, map(x->x.columns, (c,cs...))...)...,)) -vcat{D<:Tup,C<:NamedTuple}(c::Columns{D,C}, cs::Columns{D,C}...) = Columns{D,C}(C(map(vcat, map(x->x.columns, (c,cs...))...)...,)) +vcat(c::Columns{D,C}, cs::Columns{D,C}...) where {D<:Tup,C<:Tuple} = Columns{D,C}((map(vcat, map(x->x.columns, (c,cs...))...)...,)) +vcat(c::Columns{D,C}, cs::Columns{D,C}...) where {D<:Tup,C<:NamedTuple} = Columns{D,C}(C(map(vcat, map(x->x.columns, (c,cs...))...)...,)) function Base.vcat(c::Columns, cs::Columns...) fns = map(fieldnames, (map(x->x.columns, (c, cs...)))) @@ -145,7 +145,7 @@ function Base.vcat(c::Columns, cs::Columns...) Columns(map(vcat, map(x->x.columns, (c,cs...))...)) end -@compat abstract type SerializedColumns end +abstract type SerializedColumns end function serialize(s::AbstractSerializer, c::Columns) Base.Serializer.serialize_type(s, SerializedColumns) diff --git a/src/indexing.jl b/src/indexing.jl index 7d35fb89..769b098a 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -2,7 +2,7 @@ getindex(t::IndexedTable, idxs...) = (flush!(t); _getindex(t, idxs)) -_getindex{T,D<:Tuple}(t::IndexedTable{T,D}, idxs::D) = _getindex_scalar(t, idxs) +_getindex(t::IndexedTable{T,D}, idxs::D) where {T,D<:Tuple} = _getindex_scalar(t, idxs) _getindex(t::IndexedTable, idxs::Tuple{Vararg{Real}}) = _getindex_scalar(t, idxs) function _getindex_scalar(t, idxs) @@ -26,19 +26,19 @@ import Base: tail @inline _row_in(c1, r, i1, rI::Tuple{}, ri) = _in(c1[r],i1) range_estimate(col, idx) = 1:length(col) -range_estimate{T}(col::AbstractVector{T}, idx::T) = searchsortedfirst(col, idx):searchsortedlast(col,idx) +range_estimate(col::AbstractVector{T}, idx::T) where {T} = searchsortedfirst(col, idx):searchsortedlast(col,idx) range_estimate(col, idx::AbstractArray) = searchsortedfirst(col,first(idx)):searchsortedlast(col,last(idx)) const _fwd = Base.Order.ForwardOrdering() range_estimate(col, idx, lo, hi) = 1:length(col) -range_estimate{T}(col::AbstractVector{T}, idx::T, lo, hi) = +range_estimate(col::AbstractVector{T}, idx::T, lo, hi) where {T} = searchsortedfirst(col, idx, lo, hi, _fwd):searchsortedlast(col, idx, lo, hi, _fwd) range_estimate(col, idx::AbstractArray, lo, hi) = searchsortedfirst(col, first(idx), lo, hi, _fwd):searchsortedlast(col, last(idx), lo, hi, _fwd) isconstrange(col, idx) = false -isconstrange{T}(col::AbstractVector{T}, idx::T) = true +isconstrange(col::AbstractVector{T}, idx::T) where {T} = true isconstrange(col, idx::AbstractArray) = isequal(first(idx), last(idx)) function range_estimate(I::Columns, idxs) @@ -73,7 +73,7 @@ end Returns an iterator over data items where the given indices match. Accepts the same index arguments as `getindex`. """ -function where{N}(d::IndexedTable, idxs::Vararg{Any,N}) +function where(d::IndexedTable, idxs::Vararg{Any,N}) where N I = d.index cs = astuple(I.columns) data = d.data @@ -87,7 +87,7 @@ end Replace data values `x` with `f(x)` at each location that matches the given indices. """ -function update!{N}(f::Union{Function,Type}, d::IndexedTable, idxs::Vararg{Any,N}) +function update!(f::Union{Function,Type}, d::IndexedTable, idxs::Vararg{Any,N}) where N I = d.index cs = astuple(I.columns) data = d.data @@ -108,7 +108,7 @@ pairs(d::IndexedTable) = (d.index[i]=>d.data[i] for i in 1:length(d)) Similar to `where`, but returns an iterator giving `index=>value` pairs. `index` will be a tuple. """ -function pairs{N}(d::IndexedTable, idxs::Vararg{Any,N}) +function pairs(d::IndexedTable, idxs::Vararg{Any,N}) where N I = d.index cs = astuple(I.columns) data = d.data @@ -128,9 +128,9 @@ setindex!(t::IndexedTable, rhs::AbstractVector, I::Columns) = merge!(t, IndexedT # assigning a single item -_setindex!{T,D}(t::IndexedTable{T,D}, rhs::AbstractArray, idxs::D) = _setindex_scalar!(t, rhs, idxs) +_setindex!(t::IndexedTable{T,D}, rhs::AbstractArray, idxs::D) where {T,D} = _setindex_scalar!(t, rhs, idxs) _setindex!(t::IndexedTable, rhs::AbstractArray, idxs::Tuple{Vararg{Real}}) = _setindex_scalar!(t, rhs, idxs) -_setindex!{T,D}(t::IndexedTable{T,D}, rhs, idxs::D) = _setindex_scalar!(t, rhs, idxs) +_setindex!(t::IndexedTable{T,D}, rhs, idxs::D) where {T,D} = _setindex_scalar!(t, rhs, idxs) #_setindex!(t::IndexedTable, rhs, idxs::Tuple{Vararg{Real}}) = _setindex_scalar!(t, rhs, idxs) function _setindex_scalar!(t, rhs, idxs) @@ -144,7 +144,7 @@ end _setindex!(t::IndexedTable, rhs::IndexedTable, idxs::Tuple{Vararg{Real}}) = _setindex!(t, rhs.data, idxs) _setindex!(t::IndexedTable, rhs::IndexedTable, idxs) = _setindex!(t, rhs.data, idxs) -function _setindex!{T,D}(d::IndexedTable{T,D}, rhs::AbstractArray, idxs) +function _setindex!(d::IndexedTable{T,D}, rhs::AbstractArray, idxs) where {T,D} for idx in idxs isa(idx, AbstractVector) && (issorted(idx) || error("indices must be sorted for ranged/vector indexing")) end @@ -181,7 +181,7 @@ end # broadcast assignment of a single value into all matching locations -function _setindex!{T,D}(d::IndexedTable{T,D}, rhs, idxs) +function _setindex!(d::IndexedTable{T,D}, rhs, idxs) where {T,D} for idx in idxs isa(idx, AbstractVector) && (issorted(idx) || error("indices must be sorted for ranged/vector indexing")) end diff --git a/src/join.jl b/src/join.jl index 2693cf93..bfdfb1ed 100644 --- a/src/join.jl +++ b/src/join.jl @@ -59,7 +59,7 @@ function _naturaljoin(left::IndexedTable, right::IndexedTable, op, data) IndexedTable(I, data, presorted=true) end -map{T,S,D}(f, x::IndexedTable{T,D}, y::IndexedTable{S,D}) = naturaljoin(x, y, f) +map(f, x::IndexedTable{T,D}, y::IndexedTable{S,D}) where {T,S,D} = naturaljoin(x, y, f) # left join @@ -150,7 +150,7 @@ end # merge - union join -function count_overlap{D}(I::Columns{D}, J::Columns{D}) +function count_overlap(I::Columns{D}, J::Columns{D}) where D lI, lJ = length(I), length(J) i = j = 1 overlap = 0 @@ -178,9 +178,9 @@ function promoted_similar(x::AbstractArray, y::AbstractArray, n) end # assign y into x out-of-place -merge{T,S,D<:Tuple}(x::IndexedTable{T,D}, y::IndexedTable{S,D}; agg = IndexedTables.right) = (flush!(x);flush!(y); _merge(x, y, agg)) +merge(x::IndexedTable{T,D}, y::IndexedTable{S,D}; agg = IndexedTables.right) where {T,S,D<:Tuple} = (flush!(x);flush!(y); _merge(x, y, agg)) # merge without flush! -function _merge{T,S,D}(x::IndexedTable{T,D}, y::IndexedTable{S,D}, agg) +function _merge(x::IndexedTable{T,D}, y::IndexedTable{S,D}, agg) where {T,S,D} I, J = x.index, y.index lI, lJ = length(I), length(J) #if isless(I[end], J[1]) @@ -262,7 +262,7 @@ function merge(x::IndexedTable, xs::IndexedTable...; agg = nothing) end # merge in place -function merge!{T,S,D<:Tuple}(x::IndexedTable{T,D}, y::IndexedTable{S,D}; agg = IndexedTables.right) +function merge!(x::IndexedTable{T,D}, y::IndexedTable{S,D}; agg = IndexedTables.right) where {T,S,D<:Tuple} flush!(x) flush!(y) _merge!(x, y, agg) diff --git a/src/utils.jl b/src/utils.jl index 5b3b5608..28c6250e 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -12,7 +12,7 @@ Base.@pure astuple{T<:NamedTuple}(::Type{T}) = Tuple{T.parameters...} astuple{T<:Tuple}(::Type{T}) = T # sizehint, making sure to return first argument -_sizehint!{T}(a::Array{T,1}, n::Integer) = (sizehint!(a, n); a) +_sizehint!(a::Array{T,1}, n::Integer) where {T} = (sizehint!(a, n); a) _sizehint!(a::AbstractArray, sz::Integer) = a # argument selectors @@ -61,15 +61,15 @@ end # family of projection functions -immutable ProjFn{F} +struct ProjFn{F} f::F end (p::ProjFn)(x::Tup) = p.f(x) -immutable Proj{f} end +struct Proj{f} end -function (p::Proj{f}){f}(x::Tup) +function (p::Proj{f})(x::Tup) where f getfield(x, f) end @@ -117,9 +117,9 @@ pick(fld) = Proj{fld}() import Base: length, eltype, start, next, done -@compat abstract type AbstractProdIterator end +abstract type AbstractProdIterator end -immutable Prod2{I1, I2} <: AbstractProdIterator +struct Prod2{I1, I2} <: AbstractProdIterator a::I1 b::I2 end @@ -154,7 +154,7 @@ end next(p::Prod2, st) = prod_next(p, st) done(p::AbstractProdIterator, st) = st[3] -immutable Prod{I1, I2<:AbstractProdIterator} <: AbstractProdIterator +struct Prod{I1, I2<:AbstractProdIterator} <: AbstractProdIterator a::I1 b::I2 end @@ -162,7 +162,7 @@ end product(a, b, c...) = Prod(a, product(b, c...)) eltype{I1,I2}(::Type{Prod{I1,I2}}) = tuple_type_cons(eltype(I1), eltype(I2)) -function next{I1,I2}(p::Prod{I1,I2}, st) +function next(p::Prod{I1,I2}, st) where {I1,I2} x = prod_next(p, st) ((x[1][1],x[1][2]...), x[2]) end @@ -171,7 +171,7 @@ end sortperm_fast(x; alg=MergeSort, kwargs...) = sortperm(x, alg=alg, kwargs...) -function sortperm_fast{T<:Integer}(v::Vector{T}) +function sortperm_fast(v::Vector{T}) where T<:Integer n = length(v) if n > 1 min, max = extrema(v) @@ -183,7 +183,7 @@ function sortperm_fast{T<:Integer}(v::Vector{T}) return sortperm(v, alg=MergeSort) end -function sortperm_int_range{T<:Integer}(x::Vector{T}, rangelen, minval) +function sortperm_int_range(x::Vector{T}, rangelen, minval) where T<:Integer offs = 1 - minval n = length(x) @@ -211,7 +211,7 @@ function sort_sub_by!(v, i0, i1, by, order, temp) sort!(v, i0, i1, MergeSort, order, temp) end -function sort_sub_by!{T<:Integer}(v, i0, i1, by::Vector{T}, order, temp) +function sort_sub_by!(v, i0, i1, by::Vector{T}, order, temp) where T<:Integer min = max = by[v[i0]] @inbounds for i = i0+1:i1 val = by[v[i]] @@ -344,8 +344,8 @@ end _map_params(f, T::Type{Tuple{}},S::Type{Tuple{}}) = () -map_params{T,S}(f, ::Type{T}, ::Type{S}) = f(T,S) -map_params{T}(f, ::Type{T}) = map_params((x,y)->f(x), T, T) +map_params(f, ::Type{T}, ::Type{S}) where {T,S} = f(T,S) +map_params(f, ::Type{T}) where {T} = map_params((x,y)->f(x), T, T) @inline _tuple_type_head{T<:Tuple}(::Type{T}) = Base.tuple_type_head(T) @inline _tuple_type_tail{T<:Tuple}(::Type{T}) = Base.tuple_type_tail(T) @@ -357,7 +357,7 @@ Base.@pure function map_params{T<:Tuple,S<:Tuple}(f, ::Type{T}, ::Type{S}) Tuple{_map_params(f, T,S)...} end -_tuple_type_head{NT<: NamedTuple}(T::Type{NT}) = fieldtype(NT, 1) +_tuple_type_head(T::Type{NT}) where {NT<: NamedTuple} = fieldtype(NT, 1) Base.@pure function _tuple_type_tail{NT<: NamedTuple}(T::Type{NT}) Tuple{Base.argtail(NT.parameters...)...}