Skip to content

Commit

Permalink
Fix multi-column select! #404 (#405)
Browse files Browse the repository at this point in the history
* add allow multicol

* add tests

* add fix

* Update src/macros.jl

Co-authored-by: Bogumił Kamiński <bkamins@sgh.waw.pl>

---------

Co-authored-by: Bogumił Kamiński <bkamins@sgh.waw.pl>
  • Loading branch information
pdeffebach and bkamins authored Nov 14, 2024
1 parent bffeabb commit d93dcbd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,7 @@ end
function rselect_helper(x, args...)
x, exprs, outer_flags, kw = get_df_args_kwargs(x, args...; wrap_byrow = true)

t = (fun_to_vec(ex; gensym_names=false, outer_flags=outer_flags) for ex in exprs)
t = (fun_to_vec(ex; gensym_names=false, outer_flags=outer_flags, allow_multicol=true) for ex in exprs)
quote
$select($x, $(t...); $(kw...))
end
Expand Down Expand Up @@ -1983,7 +1983,7 @@ end
function select!_helper(x, args...)
x, exprs, outer_flags, kw = get_df_args_kwargs(x, args...; wrap_byrow = false)

t = (fun_to_vec(ex; gensym_names = false, outer_flags = outer_flags) for ex in exprs)
t = (fun_to_vec(ex; gensym_names = false, outer_flags = outer_flags, allow_multicol=true) for ex in exprs)
quote
$select!($x, $(t...); $(kw...))
end
Expand Down Expand Up @@ -2119,7 +2119,7 @@ end
function rselect!_helper(x, args...)
x, exprs, outer_flags, kw = get_df_args_kwargs(x, args...; wrap_byrow = true)

t = (fun_to_vec(ex; gensym_names=false, outer_flags=outer_flags) for ex in exprs)
t = (fun_to_vec(ex; gensym_names=false, outer_flags=outer_flags, allow_multicol=true) for ex in exprs)
quote
$select!($x, $(t...); $(kw...))
end
Expand Down
61 changes: 61 additions & 0 deletions test/multicol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,67 @@ df = DataFrame(A = 1, AA = 2, B = 3)
@test t == DataFrame(AA = 2, B = 3)
end

@testset "rselect_multi" begin
df = DataFrame(A = 1, AA = 2, B = 3)

t = @rselect df Not(:A)
@test t == DataFrame(AA = 2, B = 3)

t = @rselect df All()
@test t == DataFrame(A = 1, AA = 2, B = 3)

t = @rselect df Cols(r"A")
@test t == DataFrame(A = 1, AA = 2)

t = @rselect df Between(:AA, :B)
@test t == DataFrame(AA = 2, B = 3)
end

@testset "select!_multi" begin
df = DataFrame(A = 1, AA = 2, B = 3)

@select! df Not(:A)
@test df == DataFrame(AA = 2, B = 3)

df = DataFrame(A = 1, AA = 2, B = 3)

@select! df All()
@test df == DataFrame(A = 1, AA = 2, B = 3)

df = DataFrame(A = 1, AA = 2, B = 3)

@select! df Cols(r"A")
@test df == DataFrame(A = 1, AA = 2)

df = DataFrame(A = 1, AA = 2, B = 3)

@select! df Between(:AA, :B)
@test df == DataFrame(AA = 2, B = 3)
end

@testset "rselect!_multi" begin
df = DataFrame(A = 1, AA = 2, B = 3)

@rselect! df Not(:A)
@test df == DataFrame(AA = 2, B = 3)

df = DataFrame(A = 1, AA = 2, B = 3)

@rselect! df All()
@test df == DataFrame(A = 1, AA = 2, B = 3)

df = DataFrame(A = 1, AA = 2, B = 3)

@rselect! df Cols(r"A")
@test df == DataFrame(A = 1, AA = 2)

df = DataFrame(A = 1, AA = 2, B = 3)

@rselect! df Between(:AA, :B)
@test df == DataFrame(AA = 2, B = 3)
end


@testset "othermacros_multi" begin
df = DataFrame(A = 1, AA = 2, B = 3)

Expand Down

2 comments on commit d93dcbd

@pdeffebach
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Version 0.15.3 already exists

Please sign in to comment.