Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.
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
25 changes: 16 additions & 9 deletions src/pooleddataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,15 @@ end
##
##############################################################################

function compact{T,R<:Integer,N}(d::PooledDataArray{T,R,N})
sz = length(d.pool)

function compactreftype(sz)
REFTYPE = sz <= typemax(UInt8) ? UInt8 :
sz <= typemax(UInt16) ? UInt16 :
sz <= typemax(UInt32) ? UInt32 :
UInt64
end

function compact{T,R<:Integer,N}(d::PooledDataArray{T,R,N})
REFTYPE = compactreftype(length(d.pool))

if REFTYPE == R
return d
Expand Down Expand Up @@ -618,12 +620,7 @@ Perm{O<:Base.Sort.Ordering}(o::O, v::PooledDataVector) = FastPerm(o, v)
function PooledDataVecs{S,Q<:Integer,R<:Integer,N}(v1::PooledDataArray{S,Q,N},
v2::PooledDataArray{S,R,N})
pool = sort(unique([v1.pool; v2.pool]))
sz = length(pool)

REFTYPE = sz <= typemax(UInt8) ? UInt8 :
sz <= typemax(UInt16) ? UInt16 :
sz <= typemax(UInt32) ? UInt32 :
UInt64
REFTYPE = compactreftype(length(pool))

tidx1 = convert(Vector{REFTYPE}, findat(pool, v1.pool))
tidx2 = convert(Vector{REFTYPE}, findat(pool, v2.pool))
Expand Down Expand Up @@ -829,3 +826,13 @@ function dropna{T}(pdv::PooledDataVector{T})
resize!(res, total)
return res
end

function Base.vcat{T,R,N}(p1::PooledDataArray{T,R,N}, p2::PooledDataArray...)
pa = (p1, p2...)
pool = unique(T[[p.pool for p in pa]...;])

idx = [indexin(p.pool, pool)[p.refs] for p in pa]

refs = Array{DEFAULT_POOLED_REF_TYPE,N}([idx...;])
PooledDataArray(RefArray(refs), pool)
end
21 changes: 21 additions & 0 deletions test/pooleddataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,25 @@ module TestPDA
pda = @pdata([NA, "A", "B", "C", "A", "B"])
@test isequal(Base.permute!!(copy(pda), [2, 5, 3, 6, 4, 1]), @pdata(["A", "A", "B", "B", "C", NA]))
@test isequal(Base.ipermute!!(copy(pda), [6, 1, 3, 5, 2, 4]), @pdata(["A", "A", "B", "B", "C", NA]))

a1 = 1:200
a2 = 100:300
pa1 = PooledDataArray(a1)
pa2 = PooledDataArray(a2)
ca1 = compact(pa1)
ca2 = compact(pa2)
r = vcat(ca1, ca2)
@test r == vcat(a1, a2)
@test isa(r, PooledDataArray{Int,DataArrays.DEFAULT_POOLED_REF_TYPE})
@test isa(vcat(ca1, pa2), PooledDataArray{Int,DataArrays.DEFAULT_POOLED_REF_TYPE})

a1 = Array{Int}(2,3,4,5)
a2 = Array{Int}(3,3,4,5)
a1[1:end] = length(a1):-1:1
a2[1:end] = (1:length(a2)) + 10
ca1 = compact(PooledDataArray(a1))
ca2 = compact(PooledDataArray(a2))
r = vcat(ca1, ca2)
@test r == vcat(a1, a2)
@test isa(r, PooledDataArray{Int,DataArrays.DEFAULT_POOLED_REF_TYPE,4})
end