Skip to content

Commit

Permalink
write errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeffebach committed Oct 31, 2023
1 parent b15eb24 commit 51c2792
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/parsing.jl
Original file line number Diff line number Diff line change
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
# so we test that this throws an error
@test_throws UndefVarError t = DataFramesMeta.@transform df :c = sum(AsTable([:a]))

# 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

0 comments on commit 51c2792

Please sign in to comment.