Skip to content

do not pass empty vector to Tables.columntable#3435

Merged
bkamins merged 3 commits intomainfrom
bk/empty_vector
Apr 10, 2024
Merged

do not pass empty vector to Tables.columntable#3435
bkamins merged 3 commits intomainfrom
bk/empty_vector

Conversation

@bkamins
Copy link
Copy Markdown
Member

@bkamins bkamins commented Apr 9, 2024

@nalimilan - following your comment on Slack this is a DataFrames.jl fix. In it I propose even more extreme approach - do not generate any columns if the returned vector is empty. This will make consistent behavior of DataFrame, and GroupedDataFrame, as it is now a corner case when they differ.

The behavior before this PR is:

julia> df = DataFrame(a=[1,2,3])
3×1 DataFrame
 Row │ a
     │ Int64
─────┼───────
   1 │     1
   2 │     2
   3 │     3

julia> gdf = groupby(df, :a)
GroupedDataFrame with 3 groups based on key: a
First Group (1 row): a = 1
 Row │ a
     │ Int64
─────┼───────
   1 │     1
⋮
Last Group (1 row): a = 3
 Row │ a
     │ Int64
─────┼───────
   1 │     3

julia> combine(df, :a => (a -> [(b=1,c=2)][1:0]) => AsTable) # we try to identify columns
0×2 DataFrame
 Row │ b      c
     │ Int64  Int64
─────┴──────────────

julia> combine(gdf, :a => (a -> [(b=1,c=2)][1:0]) => AsTable) # we just ignore empty groups
0×1 DataFrame
 Row │ a
     │ Int64
─────┴───────

TODO: tests/news - after we decide what we want

@bkamins bkamins added the ecosystem Issues in DataFrames.jl ecosystem label Apr 9, 2024
@bkamins
Copy link
Copy Markdown
Member Author

bkamins commented Apr 9, 2024

@nalimilan - this should be good to review

@bkamins bkamins merged commit 8c1d98e into main Apr 10, 2024
@bkamins bkamins deleted the bk/empty_vector branch April 10, 2024 18:07
@bkamins
Copy link
Copy Markdown
Member Author

bkamins commented Apr 10, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem Issues in DataFrames.jl ecosystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants