diff --git a/src/parsing.jl b/src/parsing.jl index 5c48f90b..4f1b9e00 100644 --- a/src/parsing.jl +++ b/src/parsing.jl @@ -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] @@ -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 @@ -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 diff --git a/src/parsing_astable.jl b/src/parsing_astable.jl index 16987d69..fa44bf51 100644 --- a/src/parsing_astable.jl +++ b/src/parsing_astable.jl @@ -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 diff --git a/test/import.jl b/test/import.jl new file mode 100644 index 00000000..3cd6b741 --- /dev/null +++ b/test/import.jl @@ -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 \ No newline at end of file