Assign to multiple columns in `@transform` (and other applicables)

Open
#419 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
julia
Domain
data

Research direction

Start with the existing @rtransform! and @astable entry points, and compare their behavior with DataFrames' transform! multiple-column assignment shown in the issue. Determine whether the concise @astable assignments can support tuple or iterable expansion to multiple target columns; done means both examples work as described.

Written by the indexing model from the issue text.

Description

In DataFrames proper I can do something like

df = DataFrame(point = [(1, 2), (2, 3), (3, 4)])
transform!(df, :point => [:x, :y])
transform!(df, [:x, :y] => ByRow((x, y) -> expensive_computation(x, y)) => [:res1, :res2])

which automatically expands the returned iterable onto two new columns. As far as I can see, this would map to

df = DataFrame(point = [(1, 2), (2, 3), (3, 4)])
@rtransform!(df, [:x, :y]=:point)
@rtransform!(df, [:res1, :res2]=expensive_computation(:x,:y))

in DataFramesMeta, however, this does not seem to be currently possible.
It is possible to fuse these operations with @astable:

df = DataFrame(point = [(1, 2), (2, 3), (3, 4)])
@rtransform!(df, @astable begin
    :x = :point[1]
    :y = :point[2]
    intermediate = expensive_computation(:x, :y)
    :res1 = intermediate[1]
    :res2 = intermediate[2]
end)

but then again, being able to write this as

@rtransform!(df, @astable begin
    :x, :y = :point
    :res1, :res2 = expensive_computation(:x, :y)
end)

Would be much more concise. Is there a reason that this behaviour is not implemented?

Dominant language
Julia
Stars
495
Forks
56
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaData/DataFramesMeta.jl

All issues in JuliaData/DataFramesMeta.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.