Skip to content

Commit

Permalink
Merge pull request #273 from queryverse/fix-mutate
Browse files Browse the repository at this point in the history
Fix escaping issue with @Mutate
  • Loading branch information
davidanthoff authored Aug 2, 2019
2 parents 2d9123a + fc06eb3 commit e96caab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/table_query_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ julia> df |> @mutate(bar = _.foo + 2 * _.bar, bat = "com" * _.bat) |> DataFrame
macro mutate(args...)
prev = :_
for arg in args
prev = :( merge($prev, ($(esc(arg.args[1])) = $(arg.args[2]),)) )
prev = :( Base.merge($prev, ($(arg.args[1]) = $(arg.args[2]),)) )
end
return :( Query.@map( $prev ) )

return :( Query.@map( $prev ) ) |> esc
end

macro datatype(str)
Expand Down
4 changes: 4 additions & 0 deletions test/test_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ end
@test DataFrame(df |> @mutate(foo = 1)) == DataFrame(foo=[1,1,1], bar=[3.,2.,1.], bat=["a","b","c"])
@test DataFrame(df |> @mutate(bar = _.foo - 2 * _.bar, fat = _.bat * _.bat)) == DataFrame(foo=[1,2,3], bar=[-5.,-2.,1.], bat=["a","b","c"], fat=["aa","bb","cc"])

# test a closure

closure_val = 1
@test DataFrame(df |> @mutate(foo = closure_val)) == DataFrame(foo=[1,1,1], bar=[3.,2.,1.], bat=["a","b","c"])
end

0 comments on commit e96caab

Please sign in to comment.