Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for keyword arguments #179

Open
pdeffebach opened this issue Sep 29, 2020 · 9 comments
Open

Allow for keyword arguments #179

pdeffebach opened this issue Sep 29, 2020 · 9 comments
Milestone

Comments

@pdeffebach
Copy link
Collaborator

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
Copy link
Collaborator Author

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

@pdeffebach
Copy link
Collaborator Author

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.

@bkamins
Copy link
Member

bkamins commented Aug 13, 2021

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

@pdeffebach
Copy link
Collaborator Author

  • 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).

@bkamins
Copy link
Member

bkamins commented Aug 13, 2021

So why do you need:

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

and not just e.g.:

@kwargs a = 1, b = 2

?

@pdeffebach
Copy link
Collaborator Author

@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)),)
()

@bkamins
Copy link
Member

bkamins commented Aug 13, 2021

Then why not?

@kwarg a = 1
@kwarg b = 1

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

@hdavid16
Copy link

hdavid16 commented Aug 8, 2022

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.

@pdeffebach
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants