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

RFC: Preparation for Julia 0.6 #1164

Merged
merged 13 commits into from
Mar 11, 2017
Prev Previous commit
Remove unnecessary compats, add necessary ones
ararslan committed Mar 11, 2017

Verified

This commit was signed with the committer’s verified signature.
ararslan Alex Arslan
commit 53932cad378e2a0d1384b505e171e14adc90a6a7
12 changes: 6 additions & 6 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
@@ -165,10 +165,10 @@ rename(f::Function, df::AbstractDataFrame)
```julia
df = DataFrame(i = 1:10, x = rand(10), y = rand(["a", "b", "c"], 10))
rename(x -> @compat(Symbol)(uppercase(string(x))), df)
rename(df, @compat(Dict(:i=>:A, :x=>:X)))
rename(x -> Symbol(uppercase(string(x))), df)
rename(df, Dict(:i=>:A, :x=>:X))
rename(df, :y, :Y)
rename!(df, @compat(Dict(:i=>:A, :x=>:X)))
rename!(df, Dict(:i=>:A, :x=>:X))
```
"""
@@ -231,10 +231,10 @@ Base.ndims(::AbstractDataFrame) = 2
Base.similar(df::AbstractDataFrame, dims::Int) =
DataFrame(Any[similar(x, dims) for x in columns(df)], copy(index(df)))

nas{T}(dv::AbstractArray{T}, dims::@compat(Union{Int, Tuple{Vararg{Int}}})) = # TODO move to datavector.jl?
nas{T}(dv::AbstractArray{T}, dims::Union{Int, Tuple{Vararg{Int}}}) = # TODO move to datavector.jl?
DataArray(Array{T}(dims), trues(dims))

nas{T,R}(dv::PooledDataArray{T,R}, dims::@compat(Union{Int, Tuple{Vararg{Int}}})) =
nas{T,R}(dv::PooledDataArray{T,R}, dims::Union{Int, Tuple{Vararg{Int}}}) =
PooledDataArray(DataArrays.RefArray(zeros(R, dims)), dv.pool)

nas(df::AbstractDataFrame, dims::Int) =
@@ -772,7 +772,7 @@ function Base.hash(df::AbstractDataFrame)
for i in 1:size(df, 2)
h = hash(df[i], h)
end
return @compat UInt(h)
return UInt(h)
end


2 changes: 1 addition & 1 deletion src/abstractdataframe/io.jl
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ function writetable(filename::AbstractString,
# When 'append'-ing to a nonempty file,
# 'header' triggers a check for matching colnames
if header
if any(i -> @compat(Symbol(file_df[1, i])) != index(df)[i], 1:size(df, 2))
if any(i -> Symbol(file_df[1, i]) != index(df)[i], 1:size(df, 2))
throw(KeyError("Column names don't match names in file"))
end

2 changes: 1 addition & 1 deletion src/abstractdataframe/join.jl
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ join(name, job, kind = :cross)
"""
function Base.join(df1::AbstractDataFrame,
df2::AbstractDataFrame;
on::@compat(Union{Symbol, Vector{Symbol}}) = Symbol[],
on::Union{Symbol, Vector{Symbol}} = Symbol[],
kind::Symbol = :inner)
if kind == :cross
if on != Symbol[]
10 changes: 5 additions & 5 deletions src/abstractdataframe/reshape.jl
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ end
Stacks a DataFrame; convert from a wide to long format; see
`stack`.
"""
melt(df::AbstractDataFrame, id_vars::@compat(Union{Int,Symbol})) = melt(df, [id_vars])
melt(df::AbstractDataFrame, id_vars::Union{Int,Symbol}) = melt(df, [id_vars])
function melt(df::AbstractDataFrame, id_vars)
id_inds = index(df)[id_vars]
stack(df, _setdiff(1:ncol(df), id_inds), id_inds)
@@ -173,8 +173,8 @@ function unstack(df::AbstractDataFrame, rowkey::Int, colkey::Int, value::Int)
payload = DataFrame(Any[DataArray(eltype(valuecol), Nrow) for i in 1:Ncol], map(Symbol, keycol.pool))
nowarning = true
for k in 1:nrow(df)
j = @compat Int(keycol.refs[k])
i = @compat Int(refkeycol.refs[k])
j = Int(keycol.refs[k])
i = Int(refkeycol.refs[k])
if i > 0 && j > 0
if nowarning && !isna(payload[j][i])
warn("Duplicate entries in unstack.")
@@ -206,10 +206,10 @@ function unstack(df::AbstractDataFrame, colkey::Int, value::Int)
keys = unique(keycol)
Nrow = length(g)
Ncol = length(keycol.pool)
df2 = DataFrame(Any[DataArray(fill(valuecol[1], Nrow), fill(true, Nrow)) for i in 1:Ncol], map(@compat(Symbol), keycol.pool))
df2 = DataFrame(Any[DataArray(fill(valuecol[1], Nrow), fill(true, Nrow)) for i in 1:Ncol], map(Symbol, keycol.pool))
nowarning = true
for k in 1:nrow(df)
j = @compat Int(keycol.refs[k])
j = Int(keycol.refs[k])
i = rowkey[k]
if i > 0 && j > 0
if nowarning && !isna(df2[j][i])
11 changes: 5 additions & 6 deletions src/abstractdataframe/show.jl
Original file line number Diff line number Diff line change
@@ -38,12 +38,11 @@ let
return position(io)
end
ourstrwidth(x::AbstractString) = strwidth(x) + 2 # -> Int
myconv = VERSION < v"0.4-" ? convert : Base.unsafe_convert
ourstrwidth(s::Symbol) =
@compat Int(ccall(:u8_strwidth,
Csize_t,
(Ptr{UInt8}, ),
myconv(Ptr{UInt8}, s)))
Int(ccall(:u8_strwidth,
Csize_t,
(Ptr{UInt8}, ),
Base.unsafe_convert(Ptr{UInt8}, s)))
end

#' @description
@@ -322,7 +321,7 @@ function showrows(io::IO,
rowindices2::AbstractVector{Int},
maxwidths::Vector{Int},
splitchunks::Bool = false,
rowlabel::Symbol = @compat(Symbol("Row")),
rowlabel::Symbol = Symbol("Row"),
displaysummary::Bool = true) # -> Void
ncols = size(df, 2)

4 changes: 2 additions & 2 deletions src/abstractdataframe/sort.jl
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ ordering(col::ColumnIndex, lt::Function, by::Function, rev::Bool, order::Orderin
# the permutation induced by this ordering is used to
# sort the original (presumably larger) DataFrame

type DFPerm{O<:@compat(Union{Ordering, AbstractVector}), DF<:AbstractDataFrame} <: Ordering
type DFPerm{O<:Union{Ordering, AbstractVector}, DF<:AbstractDataFrame} <: Ordering
ord::O
df::DF
end
@@ -306,7 +306,7 @@ for s in [:(Base.sort), :(Base.sortperm)]
end

Base.sort(df::AbstractDataFrame, a::Algorithm, o::Ordering) = df[sortperm(df, a, o),:]
Base.sortperm(df::AbstractDataFrame, a::Algorithm, o::@compat(Union{Perm,DFPerm})) = sort!([1:size(df, 1);], a, o)
Base.sortperm(df::AbstractDataFrame, a::Algorithm, o::Union{Perm,DFPerm}) = sort!([1:size(df, 1);], a, o)
Base.sortperm(df::AbstractDataFrame, a::Algorithm, o::Ordering) = sortperm(df, a, DFPerm(o,df))

# Extras to speed up sorting
18 changes: 9 additions & 9 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ end
# Initialize from a Vector of Associatives (aka list of dicts)
function DataFrame{D <: Associative}(ds::Vector{D}, ks::Vector)
#get column eltypes
col_eltypes = Type[@compat(Union{}) for _ = 1:length(ks)]
col_eltypes = Type[Union{} for _ = 1:length(ks)]
for d in ds
for (i,k) in enumerate(ks)
# TODO: check for user-defined "NA" values, ala pandas
@@ -173,7 +173,7 @@ function DataFrame{D <: Associative}(ds::Vector{D}, ks::Vector)
end
end
end
col_eltypes[col_eltypes .== @compat(Union{})] = Any
col_eltypes[col_eltypes .== Union{}] = Any

# create empty DataFrame, and fill
df = DataFrame(col_eltypes, ks, length(ds))
@@ -221,7 +221,7 @@ ncol(df::DataFrame) = length(index(df))
# Let getindex(df.columns[j], row_inds) from AbstractDataVector() handle
# the resolution of row indices

const ColumnIndex = @compat(Union{Real, Symbol})
const ColumnIndex = Union{Real, Symbol}

# df[SingleColumnIndex] => AbstractDataVector
function Base.getindex(df::DataFrame, col_ind::ColumnIndex)
@@ -267,7 +267,7 @@ end

# df[:, SingleColumnIndex] => (Sub)?AbstractVector
# df[:, MultiColumnIndex] => (Sub)?DataFrame
Base.getindex{T<:ColumnIndex}(df::DataFrame, row_inds::Colon, col_inds::@compat(Union{T, AbstractVector{T}})) = df[col_inds]
Base.getindex{T<:ColumnIndex}(df::DataFrame, row_inds::Colon, col_inds::Union{T, AbstractVector{T}}) = df[col_inds]

# df[SingleRowIndex, :] => (Sub)?DataFrame
Base.getindex(df::DataFrame, row_ind::Real, col_inds::Colon) = df[[row_ind], col_inds]
@@ -289,11 +289,11 @@ Base.getindex(df::DataFrame, ::Colon, ::Colon) = copy(df)

isnextcol(df::DataFrame, col_ind::Symbol) = true
function isnextcol(df::DataFrame, col_ind::Real)
return ncol(df) + 1 == @compat Int(col_ind)
return ncol(df) + 1 == Int(col_ind)
end

function nextcolname(df::DataFrame)
return @compat(Symbol(string("x", ncol(df) + 1)))
return Symbol(string("x", ncol(df) + 1))
end

# Will automatically add a new column if needed
@@ -675,7 +675,7 @@ Base.delete!(df::DataFrame, c::Int) = delete!(df, [c])
Base.delete!(df::DataFrame, c::Any) = delete!(df, index(df)[c])

# deleterows!()
function deleterows!(df::DataFrame, ind::@compat(Union{Integer, UnitRange{Int}}))
function deleterows!(df::DataFrame, ind::Union{Integer, UnitRange{Int}})
for i in 1:ncol(df)
df.columns[i] = deleteat!(df.columns[i], ind)
end
@@ -760,12 +760,12 @@ end

pool(a::AbstractVector) = compact(PooledDataArray(a))

function pool!(df::DataFrame, cname::@compat(Union{Integer, Symbol}))
function pool!(df::DataFrame, cname::Union{Integer, Symbol})
df[cname] = pool(df[cname])
return
end

function pool!{T <: @compat(Union{Integer, Symbol})}(df::DataFrame, cnames::Vector{T})
function pool!{T <: Union{Integer, Symbol}}(df::DataFrame, cnames::Vector{T})
for cname in cnames
df[cname] = pool(df[cname])
end
8 changes: 4 additions & 4 deletions src/dataframe/io.jl
Original file line number Diff line number Diff line change
@@ -397,7 +397,7 @@ function bytestotype{N <: Integer,

while index > left
if UInt32('0') <= byte <= UInt32('9')
value += (byte - @compat(UInt8('0'))) * power
value += (byte - UInt8('0')) * power
power *= 10
else
return value, false, false
@@ -411,7 +411,7 @@ function bytestotype{N <: Integer,
elseif byte == UInt32('+')
return value, left < right, false
elseif UInt32('0') <= byte <= UInt32('9')
value += (byte - @compat(UInt8('0'))) * power
value += (byte - UInt8('0')) * power
return value, true, false
else
return value, false, false
@@ -757,7 +757,7 @@ function readtable!(p::ParsedCSV,

# Extract the header
if o.header
bytes, fields, rows, nextchr = readnrows!(p, io, @compat(Int64(1)), o, d, nextchr)
bytes, fields, rows, nextchr = readnrows!(p, io, Int64(1), o, d, nextchr)

# Insert column names from header if none present
if isempty(o.names)
@@ -766,7 +766,7 @@ function readtable!(p::ParsedCSV,
end

# Parse main data set
bytes, fields, rows, nextchr = readnrows!(p, io, @compat(Int64(nrows)), o, d, nextchr)
bytes, fields, rows, nextchr = readnrows!(p, io, Int64(nrows), o, d, nextchr)

# Sanity checks
bytes != 0 || error("Failed to read any bytes.")
2 changes: 1 addition & 1 deletion src/dataframerow/dataframerow.jl
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ Base.length(r::DataFrameRow) = size(r.df, 2)

Base.endof(r::DataFrameRow) = size(r.df, 2)

Base.collect(r::DataFrameRow) = @compat Tuple{Symbol, Any}[x for x in r]
Base.collect(r::DataFrameRow) = Tuple{Symbol, Any}[x for x in r]

Base.start(r::DataFrameRow) = 1

4 changes: 2 additions & 2 deletions src/groupeddataframe/grouping.jl
Original file line number Diff line number Diff line change
@@ -379,8 +379,8 @@ end

# Groups DataFrame by cols before applying aggregate
function aggregate{S <: ColumnIndex, T <:Function}(d::AbstractDataFrame,
cols::@compat(Union{S, AbstractVector{S}}),
fs::@compat(Union{T, Vector{T}}))
cols::Union{S, AbstractVector{S}},
fs::Union{T, Vector{T}})
aggregate(groupby(d, cols), fs)
end

2 changes: 1 addition & 1 deletion src/other/index.jl
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ function Base.insert!(x::Index, idx::Integer, nm::Symbol)
end

Base.getindex(x::Index, idx::Symbol) = x.lookup[idx]
Base.getindex(x::AbstractIndex, idx::Real) = @compat Int(idx)
Base.getindex(x::AbstractIndex, idx::Real) = Int(idx)
Base.getindex(x::AbstractIndex, idx::AbstractDataVector{Bool}) = getindex(x, convert(Array, idx, false))
Base.getindex{T}(x::AbstractIndex, idx::AbstractDataVector{T}) = getindex(x, dropna(idx))
Base.getindex(x::AbstractIndex, idx::AbstractVector{Bool}) = find(idx)
2 changes: 1 addition & 1 deletion src/other/utils.jl
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ function identifier(s::AbstractString)
if !isidentifier(s)
s = makeidentifier(s)
end
@compat(Symbol(in(s, RESERVED_WORDS) ? "_"*s : s))
Symbol(in(s, RESERVED_WORDS) ? "_"*s : s)
end

function makeidentifier(s::AbstractString)
8 changes: 4 additions & 4 deletions src/statsmodels/formula.jl
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ type ModelFrame
contrasts::Dict{Symbol, ContrastsMatrix}
end

const AbstractFloatMatrix{T<:AbstractFloat} = AbstractMatrix{T}
@compat const AbstractFloatMatrix{T<:AbstractFloat} = AbstractMatrix{T}

type ModelMatrix{T <: AbstractFloatMatrix}
m::T
@@ -116,7 +116,7 @@ end
dospecials(a::Any) = a

## Distribution of & over +
const distributive = @compat Dict(:& => :+)
const distributive = Dict(:& => :+)

distribute(ex::Expr) = distribute!(copy(ex))
distribute(a::Any) = a
@@ -476,7 +476,7 @@ creating the model matrix.
factors = terms.factors

## Map eval. term name + redundancy bool to cached model matrix columns
eterm_cols = @compat Dict{Tuple{Symbol,Bool}, T}()
eterm_cols = Dict{Tuple{Symbol,Bool}, T}()
## Accumulator for each term's vector of eval. term columns.

## TODO: this method makes multiple copies of the data in the ModelFrame:
@@ -565,7 +565,7 @@ function coefnames(mf::ModelFrame)
terms = droprandomeffects(dropresponse!(mf.terms))

## strategy mirrors ModelMatrx constructor:
eterm_names = @compat Dict{Tuple{Symbol,Bool}, Vector{Compat.UTF8String}}()
eterm_names = Dict{Tuple{Symbol,Bool}, Vector{Compat.UTF8String}}()
term_names = Vector{Compat.UTF8String}[]

if terms.intercept
4 changes: 2 additions & 2 deletions test/data.jl
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@ module TestData
srand(1)
N = 20
#Cast to Int64 as rand() behavior differs between Int32/64
d1 = pdata(rand(@compat(map(Int64, 1:2)), N))
d2 = (@pdata ["A", "B", NA])[rand(@compat(map(Int64, 1:3)), N)]
d1 = pdata(rand(map(Int64, 1:2), N))
d2 = (@pdata ["A", "B", NA])[rand(map(Int64, 1:3), N)]
d3 = data(randn(N))
d4 = data(randn(N))
df7 = DataFrame(Any[d1, d2, d3], [:d1, :d2, :d3])
20 changes: 10 additions & 10 deletions test/dataframe.jl
Original file line number Diff line number Diff line change
@@ -163,17 +163,17 @@ module TestDataFrame
@test typeof(df[:, 1]) == Vector{Float64}

#test_group("Other DataFrame constructors")
df = DataFrame([@compat(Dict{Any,Any}(:a=>1, :b=>'c')),
@compat(Dict{Any,Any}(:a=>3, :b=>'d')),
@compat(Dict{Any,Any}(:a=>5))])
df = DataFrame([Dict{Any,Any}(:a=>1, :b=>'c'),
Dict{Any,Any}(:a=>3, :b=>'d'),
Dict{Any,Any}(:a=>5)])
@test size(df, 1) == 3
@test size(df, 2) == 2
@test typeof(df[:,:a]) == DataVector{Int}
@test typeof(df[:,:b]) == DataVector{Char}

df = DataFrame([@compat(Dict{Any,Any}(:a=>1, :b=>'c')),
@compat(Dict{Any,Any}(:a=>3, :b=>'d')),
@compat(Dict{Any,Any}(:a=>5))],
df = DataFrame([Dict{Any,Any}(:a=>1, :b=>'c'),
Dict{Any,Any}(:a=>3, :b=>'d'),
Dict{Any,Any}(:a=>5)],
[:a, :b])
@test size(df, 1) == 3
@test size(df, 2) == 2
@@ -214,22 +214,22 @@ module TestDataFrame
@test_throws ArgumentError push!(dfb, ("coconut",22))

dfb= DataFrame( first=[1,2], second=["apple","orange"] )
push!(dfb, @compat(Dict(:first=>3, :second=>"pear")))
push!(dfb, Dict(:first=>3, :second=>"pear"))
@test df==dfb

df=DataFrame( first=[1,2,3], second=["apple","orange","banana"] )
dfb= DataFrame( first=[1,2], second=["apple","orange"] )
push!(dfb, @compat(Dict("first"=>3, "second"=>"banana")))
push!(dfb, Dict("first"=>3, "second"=>"banana"))
@test df==dfb

df0= DataFrame( first=[1,2], second=["apple","orange"] )
dfb= DataFrame( first=[1,2], second=["apple","orange"] )
@test_throws ArgumentError push!(dfb, @compat(Dict(:first=>true, :second=>false)))
@test_throws ArgumentError push!(dfb, Dict(:first=>true, :second=>false))
@test df0==dfb

df0= DataFrame( first=[1,2], second=["apple","orange"] )
dfb= DataFrame( first=[1,2], second=["apple","orange"] )
@test_throws ArgumentError push!(dfb, @compat(Dict("first"=>"chicken", "second"=>"stuff")))
@test_throws ArgumentError push!(dfb, Dict("first"=>"chicken", "second"=>"stuff"))
@test df0==dfb

# delete!
2 changes: 1 addition & 1 deletion test/index.jl
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ end
@test names!(i, [:a,:a], allow_duplicates=true) == Index([:a,:a_1])
@test_throws ArgumentError names!(i, [:a,:a])
@test names!(i, [:a,:b]) == Index([:a,:b])
@test rename(i, @compat(Dict(:a=>:A, :b=>:B))) == Index([:A,:B])
@test rename(i, Dict(:a=>:A, :b=>:B)) == Index([:A,:B])
@test rename(i, :a, :A) == Index([:A,:b])
@test rename(i, [:a], [:A]) == Index([:A,:b])
# @test rename(i, uppercase) == Index([:A,:B])
4 changes: 2 additions & 2 deletions test/io.jl
Original file line number Diff line number Diff line change
@@ -154,8 +154,8 @@ module TestIO
osxpath = "$data/skiplines/complex_osx.csv"
winpath = "$data/skiplines/complex_windows.csv"

opts1 = @compat Dict{Any,Any}(:allowcomments => true)
opts2 = @compat Dict{Any,Any}(:skipstart => 4, :skiprows => [6, 7, 12, 14, 17], :skipblanks => false)
opts1 = Dict{Any,Any}(:allowcomments => true)
opts2 = Dict{Any,Any}(:skipstart => 4, :skiprows => [6, 7, 12, 14, 17], :skipblanks => false)

df1 = readtable(osxpath; opts1...)
# df2 = readtable(osxpath; opts2...)
4 changes: 2 additions & 2 deletions test/iteration.jl
Original file line number Diff line number Diff line change
@@ -24,11 +24,11 @@ module TestIteration
@test row[:B]-row[:A] == 1

# issue #683 (https://github.com/JuliaStats/DataFrames.jl/pull/683)
@test typeof(collect(row)) == @compat Array{Tuple{Symbol, Any}, 1}
@test typeof(collect(row)) == Array{Tuple{Symbol, Any}, 1}
end

for col in eachcol(df)
@test isa(col, @compat Tuple{Symbol, AbstractDataVector})
@test isa(col, Tuple{Symbol, AbstractDataVector})
end

@test isequal(map(x -> minimum(convert(Array, x)), eachrow(df)), Any[1,2])