Skip to content

Grouped DataFrame with array elements fails to combine  #3424

Closed
@huangyxi

Description

@huangyxi

When performing a combine operation on a DataFrame using the combine function with groupby, the output format is inconsistent based on the type of aggregation being applied. Specifically, when aggregating with the :v=>sum operation, the expected output should retain the array format for the column being aggregated. However, the current behavior results in a scalar value for the aggregated column.

julia> a = DataFrame(k=[1,1,2,2], v=[[1,2],[3,4],[5,6],[7,8]], t=[1,2,3,4])
4×3 DataFrame
 Row │ k      v       t
     │ Int64  Array  Int64
─────┼──────────────────────
   11  [1, 2]      1
   21  [3, 4]      2
   32  [5, 6]      3
   42  [7, 8]      4

julia> combine(groupby(a, :k), :v=>sum)
4×2 DataFrame
 Row │ k      v_sum
     │ Int64  Int64
─────┼──────────────
   11      4
   21      6
   32     12
   42     14

julia> combine(groupby(a, :k), :t=>sum)
2×2 DataFrame
 Row │ k      t_sum
     │ Int64  Int64
─────┼──────────────
   11      3
   22      7

Expected:

julia> combine(groupby(a, :k), :v=>sum)
2×2 DataFrame
 Row │ k        v_sum
     │ Int64    Array
─────┼────────────────
   11    [4, 6]
   22  [12, 14]

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