From 61eccd9161988b3bd8e63b1a1f48b94508ddc913 Mon Sep 17 00:00:00 2001 From: Sean Garborg Date: Wed, 17 Dec 2014 18:29:10 -0700 Subject: [PATCH 1/2] copy! tests Just added to Base --- test/dataarray.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/dataarray.jl b/test/dataarray.jl index fc7e6dd..72b8f3f 100644 --- a/test/dataarray.jl +++ b/test/dataarray.jl @@ -62,11 +62,12 @@ module TestDataArray end ret end - set1 = Any[@data([1, NA, 3]), @data([NA, 5]), @data([1, 2, 3, 4, 5]), + set1 = Any[@data([1, NA, 3]), + @data([NA, 5]), @data([1, 2, 3, 4, 5]), data(Int[]), @data([NA, 5, 3]), @data([1, 5, 3])] set2 = map(nonbits, set1) - for (dest, src, bigsrc, res1, res2) in Any[set1, set2] + for (dest, src, bigsrc, emptysrc, res1, res2) in Any[set1, set2] @test isequal(copy!(copy(dest), src), res1) @test isequal(copy!(copy(dest), 1, src), res1) @test isequal(copy!(copy(dest), 2, src, 2), res2) @@ -75,6 +76,9 @@ module TestDataArray # likely forthcoming in 0.4 # @test isequal(copy!(copy(dest), 99, src, 99, 0), dest) + @test isequal(copy!(copy(dest), 1, emptysrc), dest) + @test_throws BoundsError copy!(dest, 1, emptysrc, 1) + for idx in [0, 4] @test_throws BoundsError copy!(dest, idx, src) @test_throws BoundsError copy!(dest, idx, src, 1) From 234f9da05e18cf44b012759a927a884e44253135 Mon Sep 17 00:00:00 2001 From: Sean Garborg Date: Wed, 17 Dec 2014 21:07:10 -0700 Subject: [PATCH 2/2] Track Julia 0.4 syntax --- REQUIRE | 1 + src/DataArrays.jl | 2 +- src/datavector.jl | 11 +++++++++++ src/indexing.jl | 2 +- src/pooleddataarray.jl | 2 +- test/containers.jl | 5 +++-- test/literals.jl | 14 +++++++------- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/REQUIRE b/REQUIRE index f406143..04d57c3 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ julia 0.3.0- StatsBase 0.3 +Compat 0.2.6 diff --git a/src/DataArrays.jl b/src/DataArrays.jl index b4888ac..f992b90 100644 --- a/src/DataArrays.jl +++ b/src/DataArrays.jl @@ -1,7 +1,7 @@ using StatsBase module DataArrays - using StatsBase, Base.Cartesian + using StatsBase, Base.Cartesian, Compat const DEFAULT_POOLED_REF_TYPE = Uint32 diff --git a/src/datavector.jl b/src/datavector.jl index 2992713..76d350e 100644 --- a/src/datavector.jl +++ b/src/datavector.jl @@ -169,6 +169,17 @@ function Base.append!(da::AbstractDataVector, items::AbstractVector) da end +m = VERSION < v"0.4.0-dev+2014" ? :Compat : :Base +@eval begin + function $(m).sizehint!(da::DataVector, newsz::Integer) + sizehint!(da.data, newsz) + sizehint!(da.na, newsz) + end + + $(m).sizehint!(pda::PooledDataVector, newsz::Integer) = sizehint!(pda.refs, newsz) +end +m == :Compat && export sizehint! + function Base.sizehint(da::DataVector, newsz::Integer) sizehint(da.data, newsz) sizehint(da.na, newsz) diff --git a/src/indexing.jl b/src/indexing.jl index e6c8eee..b9d7589 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -51,7 +51,7 @@ unsafe_dasetindex!(a::AbstractArray, extr, val, idx::Real) = setindex!(a, val, i # Append newpool to pool. Return indices of newpool in pool. function combine_pools!(pool, newpool) seen = Dict{eltype(pool),Int}() - sizehint(seen, length(pool)+length(newpool)) + sizehint!(seen, length(pool)+length(newpool)) # Create mapping from pool elements to indices i = 0 diff --git a/src/pooleddataarray.jl b/src/pooleddataarray.jl index 3e8dde1..ddfa48c 100644 --- a/src/pooleddataarray.jl +++ b/src/pooleddataarray.jl @@ -288,7 +288,7 @@ function Base.unique{T}(pda::PooledDataArray{T}) n = length(pda) nlevels = length(pda.pool) unique_values = Array(T, 0) - sizehint(unique_values, nlevels) + sizehint!(unique_values, nlevels) seen = Set{eltype(pda.refs)}() firstna = 0 diff --git a/test/containers.jl b/test/containers.jl index e62ad77..0af0a53 100644 --- a/test/containers.jl +++ b/test/containers.jl @@ -62,6 +62,7 @@ for dv in (dv1, convert(DataVector{Number}, dv1), convert(PooledDataArray, dv1)) end ## sizehint -sizehint(@data([1.0, 2.0]), 5) -sizehint(@pdata([1.0, 2.0]), 5) +sizehint!(@data([1.0, 2.0]), 5) +sizehint!(@pdata([1.0, 2.0]), 5) + end diff --git a/test/literals.jl b/test/literals.jl index 59cb044..c9b1cfc 100644 --- a/test/literals.jl +++ b/test/literals.jl @@ -46,7 +46,7 @@ module TestLiterals dv = @data {1, NA, 3} @test isequal(dv, - DataArray({1, 0, 3}, + DataArray(Any[1, 0, 3], [false, true, false])) dm = @data [1 NA; 3 4] @@ -59,20 +59,20 @@ module TestLiterals DataArray(Float64[1 0; 3 4], [false true; false false])) @test typeof(dm) == DataMatrix{Float64} - + dm = @data [NA NA; NA NA] @test isequal(dm, DataArray(Any, 2, 2)) @test typeof(dm) == DataMatrix{Any} dm = @data {1 NA; 3 4} @test isequal(dm, - DataArray({1 0; 3 4}, + DataArray(Any[1 0; 3 4], [false true; false false])) dm = @data {1 NA; 3 4} @test isequal(dm, - DataArray({1 0; 3 4}, + DataArray(Any[1 0; 3 4], [false true; false false])) pdv = @pdata [1, NA, 3] @@ -88,7 +88,7 @@ module TestLiterals pdv = @pdata {1, NA, 3} @test isequal(pdv, - PooledDataArray({1, 0, 3}, + PooledDataArray(Any[1, 0, 3], [false, true, false])) pdv = @pdata [1 NA 3] @@ -115,7 +115,7 @@ module TestLiterals pdm = @pdata {1 NA; 3 4} @test isequal(pdm, - PooledDataArray({1 0; 3 4}, + PooledDataArray(Any[1 0; 3 4], [false true; false false])) pdm = @pdata [1 NA; @@ -126,7 +126,7 @@ module TestLiterals pdm = @pdata {1 NA; 3 4} @test isequal(pdm, - PooledDataArray({1 0; 3 4}, + PooledDataArray(Any[1 0; 3 4], [false true; false false])) dv1 = @data zeros(4)