Skip to content

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

@henrik-wolf

Description

@henrik-wolf

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions