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

Patch current_key() to work with zero row grouped data frames #6423

Merged

Conversation

DavisVaughan
Copy link
Member

Closes #6304

@DavisVaughan DavisVaughan force-pushed the fix/cur-group-zero-row-gdf branch from 56e1e83 to 6934b96 Compare August 19, 2022 15:18
# to do `vec_slice(<0-row-df>, 1L)`, which is an error.
keys
} else {
vec_slice(keys, self$get_current_group())
Copy link
Member Author

@DavisVaughan DavisVaughan Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_current_group() always returns a scalar integer.

It's a little tricky because private$keys is a zero row tibble when the original data frame is a zero row grouped-df. But we always evaluate at least 1 group in mutate(), even when the data frame is empty, so it looks like we are on group 1 when we call get_current_group(). Being on group 1 is right for when get_current_group() is used in cur_group_id() or current_rows(), but it isn't right here.

In general there are some tough edge cases with zero row grouped data frames.

@DavisVaughan DavisVaughan requested a review from hadley August 19, 2022 15:36
@DavisVaughan DavisVaughan force-pushed the fix/cur-group-zero-row-gdf branch from 6934b96 to 306dde8 Compare August 19, 2022 17:03
@DavisVaughan DavisVaughan merged commit 13226c9 into tidyverse:main Aug 19, 2022
@DavisVaughan DavisVaughan deleted the fix/cur-group-zero-row-gdf branch August 19, 2022 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cur_group() and size zero grouped data frame edge case bug
2 participants