From dee24e6f08e1f0f76c18d8bb1e85f281bed28f86 Mon Sep 17 00:00:00 2001 From: Pietro Vertechi Date: Mon, 4 Sep 2017 11:49:18 +0100 Subject: [PATCH] add kw support --- src/series.jl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/series.jl b/src/series.jl index f4cb4b8f..31191fd2 100644 --- a/src/series.jl +++ b/src/series.jl @@ -516,8 +516,9 @@ splittable_kw(key, val::Tuple, lengthGroup) = all(splittable_kw.(key, val, lengt split_kw(key, val::AbstractArray, indices) = val[indices, fill(Colon(), ndims(val)-1)...] split_kw(key, val::Tuple, indices) = Tuple(split_kw(key, v, indices) for v in val) -function build_arg_mat(x_ind, x, y, groupby) - y_mat = fill(NaN, length(keys(x_ind)), length(groupby.groupLabels)) +function groupedvec2mat(x_ind, x, y::AbstractArray, groupby, def_val = y[1]) + y_mat = Array{promote_type(eltype(y), typeof(def_val))}(length(keys(x_ind)), length(groupby.groupLabels)) + fill!(y_mat, def_val) for i in 1:length(groupby.groupLabels) xi = x[groupby.groupIds[i]] yi = y[groupby.groupIds[i]] @@ -526,6 +527,8 @@ function build_arg_mat(x_ind, x, y, groupby) return y_mat end +groupedvec2mat(x_ind, x, y::Tuple, groupby) = Tuple(groupedvec2mat(x_ind, x, v, groupby) for v in y) + group_as_matrix(t) = false # split the group into 1 series per group, and set the label and idxfilter for each @@ -558,7 +561,12 @@ group_as_matrix(t) = false end x_u = unique(x) x_ind = Dict(zip(x_u, 1:length(x_u))) + for (key,val) in d + if splittable_kw(key, val, lengthGroup) + :($key) := groupedvec2mat(x_ind, x, val, groupby) + end + end label --> reshape(groupby.groupLabels, 1, :) - typeof(g)((x_u, (build_arg_mat(x_ind, x, arg, groupby) for arg in last_args)...)) + typeof(g)((x_u, (groupedvec2mat(x_ind, x, arg, groupby, NaN) for arg in last_args)...)) end end