Skip to content

Commit

Permalink
Test groupindices, groupvars, and groupvalues with 2 grouping columns
Browse files Browse the repository at this point in the history
  • Loading branch information
jlumpe committed Aug 4, 2019
1 parent 6af44ed commit 052a145
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/grouping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,30 @@ end
@test groupindices(gd2) [missing, 2, 1, 2, 1, missing]
@test groupvars(gd2) == [:A]
@test groupvalues(gd2) DataFrame(A=[:B, :A])

df2 = DataFrame(A = vcat(df.A, df.A), B = repeat([:X, :Y], inner=6), C = 1:12)

gd = groupby_checked(df2, [:A, :B])
@inferred groupindices(gd)
@test groupindices(gd) == [1, 2, 3, 2, 3, 1, 4, 5, 6, 5, 6, 4]
@test groupvars(gd) == [:A, :B]
@test groupvalues(gd) DataFrame(A=[missing, :A, :B, missing, :A, :B], B=[:X, :X, :X, :Y, :Y, :Y])
gd2 = gd[[3,2,5]]
@inferred groupindices(gd2)
@test groupindices(gd2) [missing, 2, 1, 2, 1, missing, missing, 3, missing, 3, missing, missing]
@test groupvars(gd2) == [:A, :B]
@test groupvalues(gd2) == DataFrame(A=[:B, :A, :A], B=[:X, :X, :Y])

gd = groupby_checked(df2, [:A, :B], skipmissing=true)
@inferred groupindices(gd)
@test groupindices(gd) [missing, 1, 2, 1, 2, missing, missing, 3, 4, 3, 4, missing]
@test groupvars(gd) == [:A, :B]
@test groupvalues(gd) DataFrame(A=[:A, :B, :A, :B], B=[:X, :X, :Y, :Y])
gd2 = gd[[4,2,1]]
@inferred groupindices(gd2)
@test groupindices(gd2) [missing, 3, 2, 3, 2, missing, missing, missing, 1, missing, 1, missing]
@test groupvars(gd2) == [:A, :B]
@test groupvalues(gd2) DataFrame(A=[:B, :B, :A], B=[:Y, :X, :X])
end

end # module

0 comments on commit 052a145

Please sign in to comment.