Skip to content

Commit

Permalink
Clean up warnings in tests (#1453)
Browse files Browse the repository at this point in the history
* Clean up warnings in tests

* Changes from nalimilan's review

* Don't test on v0.6

* Logic in makeidentifier, add testset wrappers

* Resolve method ambiguity

* broadcast scalar assignment

* broadcast assignment of scalar into array

* create testsets to isolate assignments

* Use a testset, find -> findall

* Adjust indentation

* Remove Compat in tests; add explicit test dependencies

* require v0.7.0-beta2 for Statistics package

* dataframe.jl fixes
  • Loading branch information
dmbates authored and ararslan committed Jul 20, 2018
1 parent 2384c7a commit 1c468d6
Show file tree
Hide file tree
Showing 33 changed files with 1,080 additions and 1,190 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: julia

julia:
- 0.6
- 0.7
- nightly

os:
Expand Down
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
julia 0.6
julia 0.7.0-beta2
Missings 0.2.3
CategoricalArrays 0.3.6
CategoricalArrays 0.3.11
StatsBase 0.11.0
SortingAlgorithms
Reexport
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
12 changes: 1 addition & 11 deletions src/DataFrames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@ module DataFrames
##
##############################################################################

using Reexport, StatsBase, SortingAlgorithms, Compat
using Reexport, StatsBase, SortingAlgorithms, Compat, Statistics, Unicode, Printf
@reexport using CategoricalArrays, Missings
using Base.Sort, Base.Order
using Compat.Unicode, Compat.Printf
using Compat: @warn

if VERSION >= v"0.7.0-DEV.2738"
const kwpairs = pairs
else
kwpairs(x::AbstractArray) = (first(v) => last(v) for v in x)
using Compat.IOBuffer
end


##############################################################################
##
Expand Down
26 changes: 13 additions & 13 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,10 @@ Compat.axes(df, i) = axes(df)[i]

Base.ndims(::AbstractDataFrame) = 2

if VERSION >= v"0.7.0-DEV.3067"
Base.getproperty(df::AbstractDataFrame, col_ind::Symbol) = getindex(df, col_ind)
Base.setproperty!(df::AbstractDataFrame, col_ind::Symbol, x) = setindex!(df, x, col_ind)
# Private fields are never exposed since they can conflict with column names
Base.propertynames(df::AbstractDataFrame, private::Bool=false) = names(df)
end
Base.getproperty(df::AbstractDataFrame, col_ind::Symbol) = getindex(df, col_ind)
Base.setproperty!(df::AbstractDataFrame, col_ind::Symbol, x) = setindex!(df, x, col_ind)
# Private fields are never exposed since they can conflict with column names
Base.propertynames(df::AbstractDataFrame, private::Bool=false) = names(df)

##############################################################################
##
Expand Down Expand Up @@ -374,6 +372,8 @@ function Base.dump(io::IO, df::AbstractDataFrame, n::Int, indent)
end
end
end
Base.dump(io::IOContext, df::AbstractDataFrame, n::Int, indent) =
invoke(dump, Tuple{IO, AbstractDataFrame, Int, Any}, io, df, n, indent)


"""
Expand Down Expand Up @@ -468,8 +468,8 @@ end
function get_stats(col::AbstractArray{>:Missing})
nomissing = collect(skipmissing(col))

q = try quantile(nomissing, [.25, .5, .75]) catch [nothing, nothing, nothing] end
ex = try extrema(nomissing) catch (nothing, nothing) end
q = try quantile(nomissing, [.25, .5, .75]) catch; [nothing, nothing, nothing] end
ex = try extrema(nomissing) catch; (nothing, nothing) end
m = try mean(nomissing) catch end
if eltype(nomissing) <: Real
u = nothing
Expand All @@ -479,7 +479,7 @@ function get_stats(col::AbstractArray{>:Missing})

Dict(
:mean => m,
:std => try Compat.std(nomissing, mean = m) catch end,
:std => try std(nomissing, mean = m) catch end,
:min => ex[1],
:q25 => q[1],
:median => q[2],
Expand All @@ -494,8 +494,8 @@ function get_stats(col::AbstractArray{>:Missing})
end

function get_stats(col)
q = try quantile(col, [.25, .5, .75]) catch [nothing, nothing, nothing] end
ex = try extrema(col) catch (nothing, nothing) end
q = try quantile(col, [.25, .5, .75]) catch; [nothing, nothing, nothing] end
ex = try extrema(col) catch; (nothing, nothing) end
m = try mean(col) catch end
if eltype(col) <: Real
u = nothing
Expand All @@ -505,7 +505,7 @@ function get_stats(col)

Dict(
:mean => m,
:std => try Compat.std(col, mean = m) catch end,
:std => try std(col, mean = m) catch end,
:min => ex[1],
:q25 => q[1],
:median => q[2],
Expand Down Expand Up @@ -822,7 +822,7 @@ function colmissing(df::AbstractDataFrame) # -> Vector{Int}
return missing
end

function without(df::AbstractDataFrame, icols::Vector{Int})
function without(df::AbstractDataFrame, icols::Vector{<:Integer})
newcols = setdiff(1:ncol(df), icols)
df[newcols]
end
Expand Down
26 changes: 7 additions & 19 deletions src/abstractdataframe/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,13 @@ end
#
##############################################################################

if VERSION v"0.7.0-DEV.4059"
function latex_char_escape(char::Char)
if char == '\\'
return "\\textbackslash{}"
elseif char == '~'
return "\\textasciitilde{}"
else
return string('\\', char)
end
end
else
function latex_char_escape(char::AbstractString)
if char == "\\"
return "\\textbackslash{}"
elseif char == "~"
return "\\textasciitilde{}"
else
return string("\\", char)
end
function latex_char_escape(char::Char)
if char == '\\'
return "\\textbackslash{}"
elseif char == '~'
return "\\textasciitilde{}"
else
return string('\\', char)
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/abstractdataframe/join.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function update_row_maps!(left_table::AbstractDataFrame,
@inline function update!(ixs::RowIndexMap, orig_ix::Int, join_ix::Int, count::Int = 1)
n = length(ixs.orig)
resize!(ixs.orig, n+count)
ixs.orig[n+1:end] = orig_ix
ixs.orig[n+1:end] .= orig_ix
append!(ixs.join, join_ix:(join_ix+count-1))
ixs
end
Expand All @@ -153,7 +153,7 @@ function update_row_maps!(left_table::AbstractDataFrame,
ixs
end
@inline update!(ixs::Nothing, orig_ixs::AbstractArray) = nothing
@inline update!(mask::Vector{Bool}, orig_ixs::AbstractArray) = (mask[orig_ixs] = false)
@inline update!(mask::Vector{Bool}, orig_ixs::AbstractArray) = (mask[orig_ixs] .= false)

# iterate over left rows and compose the left<->right index map
right_dict_cols = ntuple(i -> right_dict.df[i], ncol(right_dict.df))
Expand Down
2 changes: 1 addition & 1 deletion src/abstractdataframe/reshape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ function _unstack(df::AbstractDataFrame, rowkeys::AbstractVector{Symbol},
groupidxs = [g.idx[g.starts[i]:g.ends[i]] for i in 1:length(g.starts)]
rowkey = zeros(Int, size(df, 1))
for i in 1:length(groupidxs)
rowkey[groupidxs[i]] = i
rowkey[groupidxs[i]] .= i
end
df1 = df[g.idx[g.starts], g.cols]
Nrow = length(g)
Expand Down
2 changes: 1 addition & 1 deletion src/abstractdataframe/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _getcol(x) = x
# Get an Ordering for a single column
###
function ordering(col_ord::UserColOrdering, lt::Function, by::Function, rev::Bool, order::Ordering)
for (k,v) in kwpairs(col_ord.kwargs)
for (k,v) in pairs(col_ord.kwargs)
if k == :lt; lt = v
elseif k == :by; by = v
elseif k == :rev; rev = v
Expand Down
4 changes: 2 additions & 2 deletions src/dataframe/dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function DataFrame(; kwargs...)
if isempty(kwargs)
DataFrame(Any[], Index())
else
DataFrame(kwpairs(kwargs)...)
DataFrame(pairs(kwargs)...)
end
end

Expand Down Expand Up @@ -370,7 +370,7 @@ function insert_multiple_entries!(df::DataFrame,
row_inds::AbstractVector{<:Real},
col_ind::ColumnIndex)
if haskey(index(df), col_ind)
columns(df)[index(df)[col_ind]][row_inds] = v
columns(df)[index(df)[col_ind]][row_inds] .= v
return v
else
error("Cannot assign to non-existent column: $col_ind")
Expand Down
10 changes: 4 additions & 6 deletions src/dataframerow/dataframerow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ end
Base.names(r::DataFrameRow) = names(parent(r))
_names(r::DataFrameRow) = _names(parent(r))

if VERSION >= v"0.7.0-DEV.3067"
Base.getproperty(r::DataFrameRow, idx::Symbol) = getindex(r, idx)
Base.setproperty!(r::DataFrameRow, idx::Symbol, x::Any) = setindex!(r, x, idx)
# Private fields are never exposed since they can conflict with column names
Base.propertynames(r::DataFrameRow, private::Bool=false) = names(r)
end
Base.getproperty(r::DataFrameRow, idx::Symbol) = getindex(r, idx)
Base.setproperty!(r::DataFrameRow, idx::Symbol, x::Any) = setindex!(r, x, idx)
# Private fields are never exposed since they can conflict with column names
Base.propertynames(r::DataFrameRow, private::Bool=false) = names(r)

Base.view(r::DataFrameRow, c) = DataFrameRow(parent(r)[[c]], row(r))

Expand Down
18 changes: 5 additions & 13 deletions src/groupeddataframe/grouping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,11 @@ groupby(d::AbstractDataFrame, cols;
sort::Bool = false, skipmissing::Bool = false) =
groupby(d, [cols], sort = sort, skipmissing = skipmissing)

if VERSION < v"0.7.0-DEV.5126"
Base.start(gd::GroupedDataFrame) = 1
Base.next(gd::GroupedDataFrame, state::Int) =
(view(gd.parent, gd.idx[gd.starts[state]:gd.ends[state]]),
state + 1)
Base.done(gd::GroupedDataFrame, state::Int) = state > length(gd.starts)
else
function Base.iterate(gd::GroupedDataFrame, i=1)
if i > length(gd.starts)
nothing
else
(view(gd.parent, gd.idx[gd.starts[i]:gd.ends[i]]), i+1)
end
function Base.iterate(gd::GroupedDataFrame, i=1)
if i > length(gd.starts)
nothing
else
(view(gd.parent, gd.idx[gd.starts[i]:gd.ends[i]]), i+1)
end
end

Expand Down
13 changes: 4 additions & 9 deletions src/other/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ const RESERVED_WORDS = Set(["begin", "while", "if", "for", "try",
"immutable", "do", "module", "baremodule", "using", "import", "struct",
"export", "importall", "end", "else", "elseif", "catch", "finally"])

if VERSION < v"0.7.0-DEV.3220"
push!(RESERVED_WORDS, "bitstype", "typealias", "abstract")
end

function identifier(s::AbstractString)
s = Unicode.normalize(s)
if !isidentifier(s)
Expand All @@ -19,12 +15,11 @@ function identifier(s::AbstractString)
end

function makeidentifier(s::AbstractString)
i = start(s)
done(s, i) && return "x"
(iresult = iterate(s)) === nothing && return "x"

res = IOBuffer(zeros(UInt8, sizeof(s)+1), write=true)

(c, i) = next(s, i)
(c, i) = iresult
under = if is_id_start_char(c)
write(res, c)
c == '_'
Expand All @@ -36,8 +31,8 @@ function makeidentifier(s::AbstractString)
true
end

while !done(s, i)
(c, i) = next(s, i)
while (iresult = iterate(s, i)) !== nothing
(c, i) = iresult
if c != '_' && is_id_char(c)
write(res, c)
under = false
Expand Down
2 changes: 2 additions & 0 deletions src/subdataframe/subdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ end
Base.map(f::Function, sdf::SubDataFrame) = f(sdf) # TODO: deprecate

without(sdf::SubDataFrame, c) = view(without(parent(sdf), c), rows(sdf))
# Resolve a method ambiguity
without(sdf::SubDataFrame, c::Vector{<:Integer}) = view(without(parent(sdf), c), rows(sdf))
2 changes: 2 additions & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
DataStructures
LaTeXStrings
StatsBase
CategoricalArrays
Loading

0 comments on commit 1c468d6

Please sign in to comment.