Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not pass empty vector to Tables.columntable #3435

Merged
merged 3 commits into from
Apr 10, 2024
Merged

Conversation

bkamins
Copy link
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
Member Author

bkamins commented Apr 9, 2024

@nalimilan - this should be good to review

@bkamins bkamins merged commit 8c1d98e into main Apr 10, 2024
4 of 5 checks passed
@bkamins bkamins deleted the bk/empty_vector branch April 10, 2024 18:07
@bkamins
Copy link
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