From 72d88d9a0083f496c5c571e7bf01f0072daf9589 Mon Sep 17 00:00:00 2001 From: Johan Gustafsson Date: Wed, 8 Jun 2016 17:14:59 +0200 Subject: [PATCH] expand pool of pooled columns when needed by vcat --- src/abstractdataframe/abstractdataframe.jl | 15 +++++++++++++++ test/grouping.jl | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/abstractdataframe/abstractdataframe.jl b/src/abstractdataframe/abstractdataframe.jl index cdf308f059..9be381fb9b 100644 --- a/src/abstractdataframe/abstractdataframe.jl +++ b/src/abstractdataframe/abstractdataframe.jl @@ -722,6 +722,7 @@ function _colinfo{T<:AbstractDataFrame}(dfs::Vector{T}) coltyps[idx] = promote_type(oldtyp, ct) end nonnull_ct[idx] += !_isnullable(col) + similars[idx] = expandsimilarpool(similars[idx],df[idx]) else # new column push!(colindex, cn) push!(coltyps, ct) @@ -741,6 +742,20 @@ function _colinfo{T<:AbstractDataFrame}(dfs::Vector{T}) coltyps, colnams, similars end +function expandsimilarpool{T,R<:Integer,N}(c1::PooledDataArray{T,R,N}, c2) + # expand pool to make room for all levels + pool = levels([levels(c1);levels(c2)]) + # doesn't need any refs + norefs = DataArrays.RefArray(Array{DataArrays.DEFAULT_POOLED_REF_TYPE,N}()) + # keep it compact (update the type of norefs) + compact(PooledDataArray(norefs, pool)) +end + +function expandsimilarpool(c1, c2) + c1 +end + + ############################################################################## ## ## Hashing diff --git a/test/grouping.jl b/test/grouping.jl index c8fe50f9b3..18dbd0b1f3 100644 --- a/test/grouping.jl +++ b/test/grouping.jl @@ -36,4 +36,8 @@ module TestGrouping x = pool(collect(1:20)) df = DataFrame(v1=x, v2=x) groupby(df, [:v1, :v2]) + + a = DataFrame(x=pool(1:200)) + b = DataFrame(x=pool(100:300)) + vcat(a,b) end