JuliaData / JuliaData/DataFramesMeta.jl

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.

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

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?

Contributor guide

No contributing guide indexed for this repository

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.