Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #132 from JuliaStats/track04
Browse files Browse the repository at this point in the history
Track04
  • Loading branch information
garborg committed Dec 18, 2014
2 parents fe8cead + 234f9da commit e539194
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.3.0-
StatsBase 0.3
Compat 0.2.6
2 changes: 1 addition & 1 deletion src/DataArrays.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using StatsBase

module DataArrays
using StatsBase, Base.Cartesian
using StatsBase, Base.Cartesian, Compat

const DEFAULT_POOLED_REF_TYPE = Uint32

Expand Down
11 changes: 11 additions & 0 deletions src/datavector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/pooleddataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions test/containers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions test/dataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions test/literals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit e539194

Please sign in to comment.