Skip to content

Commit

Permalink
Merge pull request #224 from pdeffebach/cols_select_fix
Browse files Browse the repository at this point in the history
Cols select fix
  • Loading branch information
pdeffebach authored Mar 1, 2021
2 parents 146d5b1 + 2a7c651 commit 1076ec5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/DataFramesMeta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ function fun_to_vec(kw::Expr; nolhs::Bool = false, gensym_names::Bool = false)
end
end
return t
elseif onearg(kw, :cols)
return kw.args[2]
else
throw(ArgumentError("Expressions not of the form `y = f(:x)` currently disallowed."))
end
Expand Down Expand Up @@ -603,7 +605,7 @@ end
"""
@transform!(d, i...)
Mutate `d` inplace to add additional columns or keys based on keyword arguments and return it.
Mutate `d` inplace to add additional columns or keys based on keyword arguments and return it.
No copies of existing columns are made.
### Arguments
Expand Down
15 changes: 12 additions & 3 deletions test/dataframes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const ≅ = isequal
@test @transform(df, n = 1).n == fill(1, nrow(df))

@test @transform(df, n = :i .* :g).n == [1, 2, 3, 8, 10]

end


Expand Down Expand Up @@ -300,7 +300,7 @@ end
n_str = "new_column"
n_sym = :new_column
n_space = "new column"

df2 = copy(df)
df2.n = df2.i .+ df2.g

Expand Down Expand Up @@ -348,7 +348,7 @@ end
df2 = copy(df)
df2.newcol = newcol
@test @select!(df2, :newcol).newcol === newcol

# mutating
df2 = @select(df, :i)
@test @select!(df, :i) === df
Expand Down Expand Up @@ -474,5 +474,14 @@ end
@test @orderby(subdf, -:i) == df[[3, 2, 1], :]
end

@testset "cols with @select fix" begin
df = DataFrame("X" => 1, "X Y Z" => 2)

@test @select(df, cols("X")) == select(df, "X")
@test @select(df, cols("X Y Z")) == select(df, "X Y Z")
@test @transform(df, cols("X")) == df
@test @transform(df, cols("X Y Z")) == df
end


end # module

0 comments on commit 1076ec5

Please sign in to comment.