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

Fix tests and deprecation warnings #14

Merged
merged 1 commit into from
May 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.3-
Compat
4 changes: 2 additions & 2 deletions src/DataFramesMeta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ end
function transform(g::GroupedDataFrame; kwargs...)
result = DataFrame(g)
idx2 = cumsum(Int[size(g[i],1) for i in 1:length(g)])
idx1 = [1, 1 + idx2[1:end-1]]
idx1 = [1; 1 + idx2[1:end-1]]
for (k, v) in kwargs
first = v(g[1])
result[k] = Array(eltype(first), size(result, 1))
Expand Down Expand Up @@ -220,7 +220,7 @@ end
##
##############################################################################

combnranges(starts, ends) = [[starts[i]:ends[i] for i in 1:length(starts)]...]
combnranges(starts, ends) = [[starts[i]:ends[i] for i in 1:length(starts)]...;]

DataFrame(g::GroupedDataFrame) = g.parent[g.idx[combnranges(g.starts, g.ends)], :]

Expand Down
5 changes: 3 additions & 2 deletions src/compositedataframe.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Compat

export AbstractCompositeDataFrame, CompositeDataFrame

Expand Down Expand Up @@ -34,15 +35,15 @@ DataFrames.DataFrame(cdf::AbstractCompositeDataFrame) = DataFrame(values(cdf), n
## basic stuff
#########################################

Base.names{T <: AbstractCompositeDataFrame}(cdf::T) = collect(T.names)
Base.names{T <: AbstractCompositeDataFrame}(cdf::T) = @compat fieldnames(T)

DataFrames.ncol(cdf::AbstractCompositeDataFrame) = length(names(cdf))
DataFrames.nrow(cdf::AbstractCompositeDataFrame) = ncol(cdf) > 0 ? length(cdf.(1))::Int : 0

Base.values(cdf::AbstractCompositeDataFrame) = Any[ cdf.(i) for i in 1:length(cdf) ]

function Base.hcat(df1::AbstractCompositeDataFrame, df2::AbstractCompositeDataFrame)
nms = DataFrames.make_unique([names(df1), names(df2)])
nms = DataFrames.make_unique([names(df1); names(df2)])
columns = Any[values(df1)..., values(df2)...]
return CompositeDataFrame(columns, nms)
end
Expand Down
11 changes: 4 additions & 7 deletions test/chaining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,15 @@ thread_left(x) = thread_left(filter(x-> !isa(x,Expr) || x.head != :line, x.args)

function thread_left(x, expr, exprs...)
if typeof(expr) == Symbol
call = Expr(:call, expr, x)

callexpr = Expr(:call, expr, x)
elseif typeof(expr) == Expr && expr.head in [:call, :macrocall]
call = Expr(expr.head, expr.args[1], x, expr.args[2:end]...)

callexpr = Expr(expr.head, expr.args[1], x, expr.args[2:end]...)
elseif typeof(expr) == Expr && expr.head == :->
call = Expr(:call, expr, x)

callexpr = Expr(:call, expr, x)
else
error("Unsupported expression $expr in @>")
end
isempty(exprs) ? call : :(@> $call $(exprs...))
isempty(exprs) ? callexpr : :(@> $callexpr $(exprs...))
end

macro >(exprs...)
Expand Down
6 changes: 3 additions & 3 deletions test/compositedataframes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ using Base.Test
using DataArrays, DataFrames
using DataFramesMeta

df = CompositeDataFrame(A = [1:3], B = [2, 1, 2])
df = CompositeDataFrame(A = [1, 2, 3], B = [2, 1, 2])
x = [2, 1, 0]

@test df.A == df[:A]
@test size(df[1:2,:]) == (2,2)
@test size(df[[1:2],:]) == (2,2)
@test size(df[[1:2], [:A]]) == (2,1)
@test size(df[[1, 2],:]) == (2,2)
@test size(df[[1, 2], [:A]]) == (2,1)
@test size(df[:, [:A]]) == (3,1)
@test size(df[:, 1:2]) == (3,2)
@test size(df[:, [1]]) == (3,1)
Expand Down
6 changes: 4 additions & 2 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ module TestDicts

using Base.Test
using DataFramesMeta
using Compat

y = 3
d = {:s => 3, :y => 44, :d => 5, :e => :(a + b)}
@compat d = Dict(:s => 3, :y => 44, :d => 5, :e => :(a + b))
@test @with(d, :s + :y) == d[:s] + d[:y]
@test @with(d, :s + y) == d[:s] + y
@test @with(d, d) == d
@test @with(d, :s + d[^(:y)]) == d[:s] + d[:y]
@test @with(d, :e.head) == d[:e].head
@test @with({:s => 3, :y => 44, :d => 5, :e => :(a + b)}, :e.head) == d[:e].head
@test @compat @with(Dict(:s => 3, :y => 44, :d => 5, :e => :(a + b)), :e.head) == d[:e].head

x = @with d begin
z = y + :y - 1
Expand Down
2 changes: 1 addition & 1 deletion test/speedtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ b = rand(n)
da = data(a)
db = data(b)
df = DataFrame(a = da, b = db)
df2 = DataFrame({a, b})
df2 = DataFrame(Any[a, b])
names!(df2, [:a, :b])

Base.values(da::DataArray) = da.data
Expand Down