Skip to content

Combining pairs(::GroupDataFrame) #2593

@ararslan

Description

@ararslan

I often find myself doing something like

combine(groupby(df, x)) do groupdf
    x = first(groupdf.x)
    # ...
end

It would be nice to be able to do something along the lines of

combine(pairs(groupby(df, x))) do groupkey, groupdf
    x = groupkey.x
    # ...
end

There is currently no such method for combine that would accept the output of pairs(::GroupedDataFrame), which is a generator over a zip of the group keys and grouped data, a type not particularly conducive to dispatch.

I spoke a bit with @bkamins about this in Slack, who noted that:

we would have to go for:

combine(::Function, ::Base.Iterators.Enumerate{<:GroupedDataFrame})

signature and require:

combine(enumerate(gdf)) do idx, sdf
    ...
end

The only downside of this pattern (fortunately not user-visible) is that it would require a completely separate code path.

Being able to access the group index would indeed be nice if it is not feasible to access the group key.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions