Comments (12)
Thank you for the bug report!
I think I understand what's going on but it will take a few days to look into it more fully.
from dataframesmeta.jl.
@pdeffebach The issue is caused by the automatic-composition mechanism you have recently introduced (that avoids creation of anonymous functions):
julia> @macroexpand @by(
df,
:x,
:a = maximum(:y .* :z)
)
quote
#= C:\Users\bogum\.julia\packages\DataFramesMeta\kWkhX\src\macros.jl:2056 =#
(DataFrames).combine((DataFrames.groupby)(df, :x), DataFramesMeta.make_source_concrete([:y, :z]) => ((∘)(maximum, .*) => :a))
end
from dataframesmeta.jl.
It's more mysterious than that, though. On 1.7.2
julia> @by(
df,
:x,
:a = maximum(:y .* :z)
)
ERROR: UndefVarError: .* not defined
Stacktrace:
[1] top-level scope
@ ~/.julia/packages/DataFramesMeta/kWkhX/src/macros.jl:2056
julia> (DataFrames).combine((DataFrames.groupby)(df, :x), DataFramesMeta.make_source_concrete([:y, :z]) => ((∘)(maximum, .*) => :a))
3×2 DataFrame
Row │ x a
│ Int64 Bool
─────┼──────────────
1 │ 1 true
2 │ 2 true
3 │ 3 false
from dataframesmeta.jl.
They display the same, but are parsed differently. The @macroexpand
version in the crucial part is:
Expr
head: Symbol call
args: Array{Any}((3,))
1: ∘ (function of type typeof(∘))
2: Symbol maximum
3: Symbol .*
while the manually passed version is parsed as:
Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol ∘
2: Symbol maximum
3: Expr
head: Symbol .
args: Array{Any}((1,))
1: Symbol *
from dataframesmeta.jl.
Okay, so one solution would be to de-construct .*
etc. to Expr(:., :*)
I will file an issue in Julia Base so people are aware of this, which I think is a bug.
from dataframesmeta.jl.
But probably it will take a long time to fix it in Base (this is unfortunately my experience), so we need some work-around in DataFramesMeta.jl anyway.
from dataframesmeta.jl.
is this still busted? what is a sensible work around?
from dataframesmeta.jl.
Sorry for not addressing this.
A workaround, which isn't really sensible, is to add "junk" in the expression
julia> @by(
df,
:x,
:a = begin 1; maximum(:y .* :z) end
)
I apologize for this. I need to be more focused on getting these parsing errors fixed.
from dataframesmeta.jl.
totally understand, just making sure I hadn't missed another solution somewhere.
FYI the problem exists in @combine()
expressions after a groupby
as well.
from dataframesmeta.jl.
Yes, it should exist for all macros.
from dataframesmeta.jl.
I'm having a hard time making an MWE
julia> macro make_composed(x, y)
esc(:(∘($x, $y)))
end;
julia> function make_composed2_helper(x, y)
Expr(:call, ∘, x, y)
end;
julia> macro make_composed2(x, y)
esc(make_composed2_helper(x, y))
end
@make_composed2 (macro with 1 method)
julia> MacroTools.@macroexpand(@make_composed(first, .*))
:(first ∘ (.*))
julia> MacroTools.@macroexpand(@make_composed2(first, .*))
:((∘)(first, (.*)))
julia> MacroTools.@macroexpand(@make_composed2(first, .*)) |> dump
Expr
head: Symbol call
args: Array{Any}((3,))
1: ∘ (function of type typeof(∘))
2: Symbol first
3: Expr
head: Symbol .
args: Array{Any}((1,))
1: Symbol *
julia> MacroTools.@macroexpand(@make_composed(first, .*)) |> dump
Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol ∘
2: Symbol first
3: Expr
head: Symbol .
args: Array{Any}((1,))
1: Symbol *
from dataframesmeta.jl.
It's really hard to tell the rules about when .*
survives and when it becomes Expr(., *)
. I will have to explore more.
from dataframesmeta.jl.
Related Issues (20)
- operators do not work inside function call inside macros HOT 3
- typos HOT 3
- Macro @rolling for scrolling through a column or columns of values? HOT 3
- Add a `@bycol` macro-flag HOT 5
- Add metadata for working with DataFrames HOT 1
- Access subdf in @by and @combine HOT 7
- Request - grouped by columns available as single values rather than vectors HOT 5
- Request: `@order` to mimic `DataFrames.order` in `@orderby` HOT 2
- Very slow `@astable` macro outside a function HOT 4
- `@with` macro clashes with `Base.@with` in Julia 1.11+ HOT 8
- `ByRow` not defined when importing DataFramesMeta HOT 1
- docs question HOT 7
- Request @rsubset_rtransform HOT 7
- Special-case `==` as with other one-argument functions HOT 2
- Add an alternative syntax escaping than `$` HOT 1
- MethodError occurred when broadcasting a string inside @astable HOT 3
- Speculative future of `@groupby` macro
- Allow reference to previously defined columns in @transform HOT 7
- `groupby` derived columns
- Add convenience function to look up a single value in a `DataFrame` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dataframesmeta.jl.