GithubHelp home page GithubHelp logo

Comments (12)

pdeffebach avatar pdeffebach commented on May 23, 2024

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.

bkamins avatar bkamins commented on May 23, 2024

@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.

pdeffebach avatar pdeffebach commented on May 23, 2024

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.

bkamins avatar bkamins commented on May 23, 2024

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.

pdeffebach avatar pdeffebach commented on May 23, 2024

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.

bkamins avatar bkamins commented on May 23, 2024

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.

tcovert avatar tcovert commented on May 23, 2024

is this still busted? what is a sensible work around?

from dataframesmeta.jl.

pdeffebach avatar pdeffebach commented on May 23, 2024

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.

tcovert avatar tcovert commented on May 23, 2024

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.

pdeffebach avatar pdeffebach commented on May 23, 2024

Yes, it should exist for all macros.

from dataframesmeta.jl.

pdeffebach avatar pdeffebach commented on May 23, 2024

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.

pdeffebach avatar pdeffebach commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.