Skip to content

Commit

Permalink
use prewalk for column replacement (#28)
Browse files Browse the repository at this point in the history
* use prewalk for column replacement

* add changelog and bump patch
  • Loading branch information
jkrumbiegel authored Oct 10, 2022
1 parent 6f7f515 commit 5508223
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.3.3

- Fixed bug when column symbols were used inside braces.

## v0.3.2

- Added `@proprow`, `@eachindex` and `@groupindices` special function macros, which required compat to be raised to DataFrames v1.4.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DataFrameMacros"
uuid = "75880514-38bc-4a95-a458-c2aea5a3a702"
authors = ["Julius Krumbiegel <[email protected]> and contributors"]
version = "0.3.2"
version = "0.3.3"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
10 changes: 2 additions & 8 deletions src/DataFrameMacros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DataFrameMacros

using Base: ident_cmp
using DataFrames: DataFrames, transform, transform!, select, select!, combine, subset, subset!, ByRow, passmissing, groupby, AsTable, DataFrame, GroupedDataFrame
using MacroTools: @capture
using MacroTools: @capture, prewalk, postwalk

export @transform, @transform!, @select, @select!, @combine, @subset, @subset!, @groupby, @sort, @sort!, @unique

Expand Down Expand Up @@ -535,7 +535,7 @@ function make_function_expr(formula, columns)
end

newsyms = map(x -> gensym(), columns)
replaced_formula = postwalk(formula) do e
replaced_formula = prewalk(formula) do e
# check first if this is an escaped symbol
# and if yes return it unwrapped
if is_escaped_symbol(e)
Expand Down Expand Up @@ -593,12 +593,6 @@ function is_simple_function_call(expr::Expr, columns)
is_simple, expr.args[1]
end

# from macrotools
walk(x, inner, outer) = outer(x)
walk(x::Expr, inner, outer) = outer(Expr(x.head, map(inner, x.args)...))
postwalk(f, x) = walk(x, x -> postwalk(f, x), f)


convert_automatic_astable_formula(x) = x
function convert_automatic_astable_formula(e::Expr)
e_replaced, assigned_symbols, gensyms = replace_assigned_symbols(e)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ end
@test @select(df, :d = maximum({{Not(:a)}})) == @select(df, :d = maximum([:b, :c]))
@test @select(df, :d = @bycol sum({{r"[bc]"}})) == @select(df, :d = @bycol sum((:b, :c)))
@test @select(df, :d = :a < maximum({{[:b, :c]}})) == @select(df, :d = :a < maximum((:b, :c)))
@test @select(df, :d = :a < maximum({{Not(:a)}})) == @select(df, :d = :a < maximum((:b, :c)))
end

@testset "special cased functions" begin
Expand Down

2 comments on commit 5508223

@jkrumbiegel
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/69830

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.3 -m "<description of version>" 5508223b756d8d50d34b5e270cef9bda7215342c
git push origin v0.3.3

Please sign in to comment.