Skip to content

Commit

Permalink
Modify duplicate names
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeffebach committed Feb 6, 2019
1 parent 7e5fb51 commit 28a4fa2
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/groupeddataframe/grouping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 28a4fa2

Please sign in to comment.