Skip to content

Commit

Permalink
Merge 750c6b8 into ecd3855
Browse files Browse the repository at this point in the history
  • Loading branch information
pdeffebach committed Aug 24, 2018
2 parents ecd3855 + 750c6b8 commit dc87f94
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -15,7 +15,7 @@ These macros improve performance and provide more convenient syntax.
`@with` allows DataFrame columns to be referenced as symbols like
`:colX` in expressions. If an expression is wrapped in `^(expr)`,
`expr` gets passed through untouched. If an expression is wrapped in
`_I_(expr)`, the column is referenced by the variable `expr` rather than
`cols(expr)`, the column is referenced by the variable `expr` rather than
a symbol. Here are some examples:

```julia
Expand All @@ -39,7 +39,7 @@ end
@with(df, df[:x .> 1, ^(:y)]) # The ^ means leave the :y alone

colref = :x
@with(df, :y + _I_(colref)) # Equivalent to df[:y] + df[colref]
@with(df, :y + cols(colref)) # Equivalent to df[:y] + df[colref]
```

This works for `AbstractDict` types, too:
Expand Down
8 changes: 5 additions & 3 deletions src/DataFramesMeta.jl
Expand Up @@ -32,6 +32,9 @@ replace_syms!(e::Expr, membernames) =
if onearg(e, :^)
e.args[2]
elseif onearg(e, :_I_)
@warn "_I_() for escaping variables is deprecated, use cols() instead"
addkey!(membernames, :($(e.args[2])))
elseif onearg(e, :cols)
addkey!(membernames, :($(e.args[2])))
elseif e.head == :quote
addkey!(membernames, Meta.quot(e.args[1]) )
Expand Down Expand Up @@ -113,7 +116,7 @@ tempfun(d[:a], d[:b])
All of the other DataFramesMeta macros are based on `@with`.
If an expression is wrapped in `^(expr)`, `expr` gets passed through untouched.
If an expression is wrapped in `_I_(expr)`, the column is referenced by the
If an expression is wrapped in `cols(expr)`, the column is referenced by the
variable `expr` rather than a symbol.
### Examples
Expand Down Expand Up @@ -160,8 +163,7 @@ julia> @with(df, df[:x .> 1, ^(:y)]) # The ^ means leave the :y alone
julia> colref = :x;
julia> @with(df, :y + _I_(colref)) # Equivalent to df[:y] + df[colref]
3-element Array{Int64,1}:
julia> @with(df, :y + cols(colref)) # Equivalent to df[:y] + df[colref]
3
3
5
Expand Down
4 changes: 2 additions & 2 deletions test/dataframes.jl
Expand Up @@ -21,9 +21,9 @@ x = @with df begin
res
end
idx = :A
@test @with(df, _I_(idx) .+ :B) == df[:A] .+ df[:B]
@test @with(df, cols(idx) .+ :B) == df[:A] .+ df[:B]
idx2 = :B
@test @with(df, _I_(idx) .+ _I_(idx2)) == df[:A] .+ df[:B]
@test @with(df, cols(idx) .+ cols(idx2)) == df[:A] .+ df[:B]

@test x == sum(df[:A] .* df[:B])
@test @with(df, df[:A .> 1, ^([:B, :A])]) == df[df[:A] .> 1, [:B, :A]]
Expand Down

0 comments on commit dc87f94

Please sign in to comment.