DataFramesMeta.jl icon indicating copy to clipboard operation
DataFramesMeta.jl copied to clipboard

Allow for keyword arguments

Open pdeffebach opened this issue 5 years ago • 9 comments

DataFrames.transform allows for keyword arguments. The current way @transform parses expressions does not allow for this.

Side note: this is a point for :x over x, but we definitely want to allow keyword arguments.

pdeffebach avatar Sep 29 '20 15:09 pdeffebach

Update, this is actually very easy to do without deciding :x vs x.

pdeffebach avatar Apr 15 '21 01:04 pdeffebach

I think this should go in before 1.0, and it should be the last thing we do before 1.0.

Proposal: With the normal function call syntax @transform(:x = 1; copycols = false). With the "block" syntax we have a @kwargs macro flag, which collects the keyword arguments as-is and passes them to the underlying functions.

pdeffebach avatar Aug 13 '21 13:08 pdeffebach

With the "block" syntax we have a @kwargs macro flag

Can you please show an example?

  1. will this be allowed multiple times or a single time in block syntax?
  2. in any position or only at the end?
  3. how multiple kwargs would be separated?
  4. Also in call syntax - would it be allowed or not?

Other than that it looks reasonable

bkamins avatar Aug 13 '21 17:08 bkamins

  • will this be allowed multiple times or a single time in block syntax?

Only once, at the end.

  • in any position or only at the end?

At the end

  • how multiple kwargs would be separated?

I think I would have @kwargs(; a = 1, b = 2). Very heavy handed. But this will be for advanced users only.

  • Also in call syntax - would it be allowed or not?

No. In call syntax they can just do @transform(df, ...; a = 1, b = 2).

pdeffebach avatar Aug 13 '21 18:08 pdeffebach

So why do you need:

@kwargs(; a = 1, b = 2)

and not just e.g.:

@kwargs a = 1, b = 2

?

bkamins avatar Aug 13 '21 18:08 bkamins

@kwargs a = 1, b = 2 parses weirdly, unfortunately

julia> macro kwargs(args...)
           esc(kwargs_helper(args...))
       end;

julia> function kwargs_helper(args...)
           @show args
           :() 
       end;

julia> @kwargs a = 1, b = 2
args = (:(a = ((1, b) = 2)),)
()

pdeffebach avatar Aug 13 '21 18:08 pdeffebach

Then why not?

@kwarg a = 1
@kwarg b = 1

and allow it multiple times and require passing only one kwarg per line?

bkamins avatar Aug 13 '21 18:08 bkamins

Having keyword arguments would be very helpful. I just reverted a bunch of my code from DataFramesMeta.jl to DataFrames.jl when I realized that I cannot use view=true on @subset or @rsubset, which was hurting performance.

hdavid16 avatar Aug 08 '22 20:08 hdavid16

Ah I'm sorry. I will try to finish this PR this week. It stalled due to a busy summer.

pdeffebach avatar Aug 15 '22 15:08 pdeffebach