Repository navigation
Find each row's group natively when a grouped verb takes rows - #459
Merged
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
jbearak
marked this pull request as ready for review
October 27, 2026 00:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
filter(),slice(), its helpers andarrange()of grouped data rebuild the result's groups from the old ones with.restore_group_metadata()'s slice policy. It first found each row's group with a loop over the groups,ids[old$.rows[[index]]] <- index, whose$and[[calls dispatch for every group. Over the 42,739 women in the first 100,000 rows of the India 2021 DHS births file, grouped bycaseid, that loop took most of the time ofslice_max(gb, b2)after #458, about 0.062 seconds, and ofarrange(gb, b2), about 0.063.This PR adds
.group_row_ids(), which the policy now calls. It reads the rows once withC_dtatools_group_rows_facts()and finds each row's group withC_dtatools_group_row_owners(), as the group checks of ADR 0115 do. Those calls give each row's position among the groups with rows when the rows hold each of the table's rows once. The empty groups of.drop = FALSEshift that position, so the group's index is the position's entry inwhich(sizes > 0L). Rows that hold some row twice or none, or that the facts do not read, keep the loop.Behavior
Results are unchanged. ADR 0121 records the decision. A traced or replaced
$or[[method for the groups' tibble or a list_of no longer sees a call for each group, as ADR 0115 already allows for the group checks.Timing
Best of three runs in fresh R sessions, in seconds, with the builds interleaved, over the first 100,000 rows of the India 2021 DHS births file grouped by
caseid. Before is main.slice_max(gb, b2)arrange(gb, b2)filter(gb, bord > 2)Tests
.group_row_ids()must give what the loop gives for each. Rows that are repeated, missing, outside the table, zero, negative or doubles must give it too, through the loop..drop = FALSEand runsfilter(),slice_max(),slice_head(),arrange()andslice()on it. Each must give the rows, group rows and keys a tibble gives.