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

allowing assignments to the right at the end of a chain #232

Closed
pfarndt opened this issue Mar 8, 2021 · 3 comments
Closed

allowing assignments to the right at the end of a chain #232

pfarndt opened this issue Mar 8, 2021 · 3 comments

Comments

@pfarndt
Copy link

pfarndt commented Mar 8, 2021

I use DataFramesMeta in Jupyter Notebooks for data analysis a lot. I prefer to develop some chain of where/select etc functions, like:

@linq data |>
  where(...) |>
  where(...) 

During development of such a workflow I usually have a first(5) at the end to check everything works ok, like:

@linq data |>
  where(...) |>
  where(...) |>
  first(5)

If everything is fine I want to the resulting data "flow" into a new variable. In principle I can do either:

newdata = @linq data |>
  where(...) |>
  where(...) 

or

@linq data |>
  where(...) |>
  where(...) 
newdata = ans

Both are not optimal. In the first version the newdata is at the very beginning of the expression, the second uses the ans variable. Ideally I would like to be able to assign to the right using some special operator (e.g. |>=), like:

@linq data |>
  where(...) |>
  where(...) |>= newdata

Would this be conceivable?

@pdeffebach
Copy link
Collaborator

I agree this would be a cool thing to have. I hate it when I write a long chain and then have to go back to the top.

I think if this feature is able to be added, it wouldn't have much to do with DataFramesMeta, and would be general.

On top of this, I think it's increasingly likely that @linq will be deprecated in favor of a dependency on Chain.jl.

Ill take a look at some options and see what's possible with macros.

@pdeffebach
Copy link
Collaborator

It looks like this is possible, for the most part, with Chain.jl

julia> using DataFramesMeta;

julia> df = DataFrame(a = [1, 2]);

julia> @chain df begin 
           @transform(y = :a)
           newdata = _
       end
2×2 DataFrame
 Row │ a      y     
     │ Int64  Int64 
─────┼──────────────
   1 │     1      1
   2 │     2      2

So this feature will be "added" if we deprecate @linq in favor of @chain

@pdeffebach
Copy link
Collaborator

Wait, that example doesn't actually work. I will still think about this.

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

2 participants