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

Fix error with ByRow on import #366

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ returns `nothing`.
get_column_expr(x) = nothing
function get_column_expr(e::Expr)
e.head == :$ && return e.args[1]
onearg(e, :AsTable) && return e
onearg(e, :AsTable) && return :($AsTable($(e.args[2])))
if onearg(e, :cols)
Base.depwarn("cols is deprecated use $DOLLAR to escape column names instead", :cols)
return e.args[2]
Expand Down Expand Up @@ -295,9 +295,9 @@ function get_source_fun(function_expr; exprflags = deepcopy(DEFAULT_FLAGS))

if exprflags[BYROW_SYM][]
if exprflags[PASSMISSING_SYM][]
fun = :(ByRow(Missings.passmissing($fun)))
fun = :($ByRow($(Missings.passmissing)($fun)))
else
fun = :(ByRow($fun))
fun = :($ByRow($fun))
end
end

Expand Down Expand Up @@ -350,7 +350,7 @@ function fun_to_vec(ex::Expr;
if final_flags[ASTABLE_SYM][]
src, fun = get_source_fun_astable(ex; exprflags = final_flags)

return :($src => $fun => AsTable)
return :($src => $fun => $AsTable)
end

if no_dest # subset and with
Expand Down
2 changes: 1 addition & 1 deletion src/parsing_astable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function get_source_fun_astable(ex; exprflags = deepcopy(DEFAULT_FLAGS))
# and if-so, making a named tuple with
# missing values
if exprflags[BYROW_SYM][]
fun = :(ByRow($fun))
fun = :($ByRow($fun))
end

return source, fun
Expand Down
34 changes: 34 additions & 0 deletions test/import.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module TestImport

using Test
import DataFrames
import DataFramesMeta

@testset "importing error" begin
df = DataFrames.DataFrame(a = [1, 2, 3])
t = DataFramesMeta.@rsubset df :a > 1
@test t == DataFrames.DataFrame(a = [2, 3])
t = DataFramesMeta.@transform df begin
@byrow :z = :a == 2
end
@test t == DataFrames.DataFrame(a = [1, 2, 3], z = [false, true, false])

t = DataFramesMeta.@rtransform df @astable begin
:b = 1
:c = 2
end
@test t == DataFrames.DataFrame(a = [1, 2, 3], b = [1, 1, 1], c = [2, 2, 2])

# AsTable on the RHS relies on the literal "AsTable" appearing
t = DataFramesMeta.@rtransform df :c = sum(AsTable([:a]))
@test t == DataFrames.DataFrame(a = [1, 2, 3], c = [1, 2, 3])

# And confusingly, if you use DataFrames.AsTable on the RHS, none of the
# special escaping happens.
# There is not a lot to do about this, unfortunately. I don't want
# to modify user-code.
@test_throws ArgumentError DataFramesMeta.@transform df :c = sum(DataFrames.AsTable([:a]))
end


end # module
Loading