From 28a4fa256f79c150d1cf9310b4fa89bdd07b2228 Mon Sep 17 00:00:00 2001
From: pdeffebach
Date: Wed, 6 Feb 2019 17:15:47 -0600
Subject: [PATCH] Modify duplicate names
---
src/groupeddataframe/grouping.jl | 34 ++++++++++++++------------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/src/groupeddataframe/grouping.jl b/src/groupeddataframe/grouping.jl
index 3e27f6bc71..aa2a4e535c 100644
--- a/src/groupeddataframe/grouping.jl
+++ b/src/groupeddataframe/grouping.jl
@@ -263,6 +263,7 @@ end
"""
combine(gd::GroupedDataFrame, cols => f...)
combine(gd::GroupedDataFrame; (colname = cols => f)...)
+ combine(gd::GroupedDataFrame; [colname = cols => f]...)
combine(gd::GroupedDataFrame, f)
combine(f, gd::GroupedDataFrame)
@@ -400,31 +401,26 @@ function combine(gd::GroupedDataFrame, args::Union{Pair, AbstractVector{<:Pair}}
# The functions just get collected
pairs_main = collect(args)
- # This next section handles duplicate names. This code is from a constructor
- # for a DataFrame and I need to figure out how toget it to do what I want
- #=
- for (i, name) if enumerate(names_pair)
- k = 1
- while true
- # we only make sure that new column name is unique
- # if df originally had duplicates in names we do not fix it
- nn = Symbol("$(name)_$k")
- if
- name = nn
- break
- end
- k += 1
- end
- end
- =#
-
# Combine the pair arguments and the keyword arguments
combined_nams = vcat(nams_kw, nams_main)
combined_pairs = vcat(pairs_kw, pairs_main)
+ # This next section handles duplicate names.
+ # We do it for the user because we auto-generate so conflicts are our fault
+ # TODO: see if we need to make this faster
+ for (i, name1) in enumerate(combined_nams)
+ k = 1
+ for (j, name2) in enumerate(combined_nams)
+ if i != j && name1 == name2
+ combined_nams[j] = Symbol("$(name2)_$(k)")
+ k += 1
+ end
+ end
+ end
+
@show nt_of_pairs = NamedTuple{Tuple(combined_nams)}(Tuple(combined_pairs))
- _combine(nt_of_pairs, gd)
+ #_combine(nt_of_pairs, gd)
end
# Wrapping automatically adds column names when the value returned