Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for column selection and renaming for GroupedDataFrame #2586

Merged
merged 2 commits into from
Dec 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/grouping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3230,6 +3230,28 @@ end
end
end

@testset "column selection and renaming" begin
df = DataFrame(id=[1, 1, 2, 3, 3, 1], x=1:6, y=11:16, z=21:26)
gdf = groupby_checked(df, :id)

@test combine(gdf, :x) == DataFrame(id=[1, 1, 1, 2, 3, 3], x=[1, 2, 6, 3, 4, 5])
@test combine(gdf, :x => :y ) == DataFrame(id=[1, 1, 1, 2, 3, 3], y=[1, 2, 6, 3, 4, 5])
@test combine(gdf, [:x, :y]) ==
DataFrame(id=[1, 1, 1, 2, 3, 3], x=[1, 2, 6, 3, 4, 5], y=[11, 12, 16, 13, 14, 15])
@test combine(gdf, [:x, :y], :z) ==
DataFrame(id=[1, 1, 1, 2, 3, 3], x=[1, 2, 6, 3, 4, 5],
y=[11, 12, 16, 13, 14, 15], z=[21, 22, 26, 23, 24, 25])
@test_throws ArgumentError combine(gdf, :x, :x)
@test_throws ArgumentError combine(gdf, :x => :y, :y)

@test select(gdf, :x) == select(df, :id, :x)
@test select(gdf, :x => :y) == select(df, :id, :x => :y)
@test select(gdf, [:x, :y]) == select(df, :id, [:x, :y])
@test select(gdf, [:x, :y], :z) == select(df, :id, [:x, :y], :z)
@test_throws ArgumentError select(gdf, :x, :x)
@test_throws ArgumentError select(gdf, :x => :y, :y)
end

@testset "corner cases of wrong transformation" begin
df = DataFrame(id=[1, 1, 2, 3, 3, 1], x=1:6)
gdf = groupby_checked(df, :id)
Expand Down