Skip to content

move grouped results into helpers out of [ - #7943

Open
ben-schwen wants to merge 1 commit into
brk/a7_SDenvfrom
brk/a8_grouped_results
Open

ben-schwen wants to merge 1 commit into
brk/a7_SDenvfrom
brk/a8_grouped_results

Conversation

@ben-schwen

Copy link
Copy Markdown
Member

Towards #852

@codecov

codecov Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.09%. Comparing base (dcea6e7) to head (6f04972).

Additional details and impacted files
@@              Coverage Diff              @@
##           brk/a7_SDenv    #7943   +/-   ##
=============================================
  Coverage         99.09%   99.09%           
=============================================
  Files                88       88           
  Lines             17422    17429    +7     
=============================================
+ Hits              17264    17271    +7     
  Misses              158      158           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ben-schwen
ben-schwen force-pushed the brk/a8_grouped_results branch from e8f6638 to 2155098 Compare October 24, 2026 23:15
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
  • HEAD=brk/a8_grouped_results much faster for as.data.table.array improved in #7019

(Plot image upload to picrd.com failed; download the artifact below to view plots)

Generated via commit 6f04972

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 37 minutes and 26 seconds
Installing different package versions 13 minutes and 43 seconds
Running and plotting the test cases 5 minutes and 49 seconds

@ben-schwen
ben-schwen force-pushed the brk/a8_grouped_results branch from 2155098 to 6f04972 Compare October 26, 2026 15:13
Comment thread R/data.table.R
Comment on lines +678 to +685
setattr(ans, "names", c(bynames, jvnames))
} else {
nonbynames = names(ans)[-seq_along(bynames)] #related to 2311. make naming of empty columns names more consistent
ww = which(!nzchar(nonbynames))
if (length(ww)) nonbynames[ww] = paste0("V", ww)
setattr(ans, "names", c(bynames, nonbynames)) # TO DO: reinvestigate bynames flowing from dogroups here and simplify
}
invisible(ans)

@MichaelChirico MichaelChirico Oct 26, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

move setattr() out of the branch?

Suggested change
setattr(ans, "names", c(bynames, jvnames))
} else {
nonbynames = names(ans)[-seq_along(bynames)] #related to 2311. make naming of empty columns names more consistent
ww = which(!nzchar(nonbynames))
if (length(ww)) nonbynames[ww] = paste0("V", ww)
setattr(ans, "names", c(bynames, nonbynames)) # TO DO: reinvestigate bynames flowing from dogroups here and simplify
}
invisible(ans)
other_ans_names <- jvnames
} else {
nonbynames = names(ans)[-seq_along(bynames)] #related to 2311. make naming of empty columns names more consistent
ww = which(!nzchar(nonbynames))
if (length(ww)) nonbynames[ww] = paste0("V", ww)
other_ans_names <- nonbynames # TO DO: reinvestigate bynames flowing from dogroups here and simplify
}
setattr(ans, "names", c(bynames, other_ans_names))
invisible(ans)

Comment thread R/data.table.R
Comment on lines +673 to +677
if (is.null(jvnames)) jvnames = character(length(ans)-length(bynames))
if (length(bynames)+length(jvnames)!=length(ans))
internal_error("jvnames is length %d but ans is %d and bynames is %d", length(jvnames), length(ans), length(bynames)) # nocov
ww = which(!nzchar(jvnames))
if (any(ww)) jvnames[ww] = paste0("V",ww)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Possibly cleaner flow:

Suggested change
if (is.null(jvnames)) jvnames = character(length(ans)-length(bynames))
if (length(bynames)+length(jvnames)!=length(ans))
internal_error("jvnames is length %d but ans is %d and bynames is %d", length(jvnames), length(ans), length(bynames)) # nocov
ww = which(!nzchar(jvnames))
if (any(ww)) jvnames[ww] = paste0("V",ww)
if (is.null(jvnames)) {
jvnames = paste0("V", seq_len(length(ans) - length(bynames)))
} else if (length(bynames) + length(jvnames) != length(ans)) {
internal_error("jvnames is length %d but ans is %d and bynames is %d", length(jvnames), length(ans), length(bynames)) # nocov
} else if (any(empty_idx <- which(!nzchar(jvnames)))) {
jvnames[empty_idx] = paste0("V", empty_idx)
}

Comment thread R/data.table.R
Comment on lines +661 to +666
if (all(cnames %chin% names_x)) {
if (verbose) {last.started.at=proc.time();catf("setkey() after the := with keyby= ... ");flush.console()}
setkeyv(x,cnames) # TO DO: setkey before grouping to get memcpy benefit.
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()}
}
else warningf("The setkey() normally performed by keyby= has been skipped (as if by= was used) because := is being used together with keyby= but the keyby= contains some expressions. To avoid this warning, use by= instead, or provide existing column names to keyby=.\n")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (all(cnames %chin% names_x)) {
if (verbose) {last.started.at=proc.time();catf("setkey() after the := with keyby= ... ");flush.console()}
setkeyv(x,cnames) # TO DO: setkey before grouping to get memcpy benefit.
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()}
}
else warningf("The setkey() normally performed by keyby= has been skipped (as if by= was used) because := is being used together with keyby= but the keyby= contains some expressions. To avoid this warning, use by= instead, or provide existing column names to keyby=.\n")
if (!all(cnames %chin% names_x)) {
warningf("The setkey() normally performed by keyby= has been skipped (as if by= was used) because := is being used together with keyby= but the keyby= contains some expressions. To avoid this warning, use by= instead, or provide existing column names to keyby=.\n")
return(invisible(x))
}
if (verbose) {last.started.at=proc.time();catf("setkey() after the := with keyby= ... ");flush.console()}
setkeyv(x, cnames) # TO DO: setkey before grouping to get memcpy benefit.
if (verbose) {cat(timetaken(last.started.at),"\n"); flush.console()}

Comment thread R/data.table.R
if (!is.null(skeys)) {
hits = unlist(lapply(paste0("__", cols_changed), grep, skeys, fixed=TRUE))
hits = skeys[unique(hits)]
for (i in seq_along(hits)) setattr(attrs, hits[i], NULL) # does by reference

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
for (i in seq_along(hits)) setattr(attrs, hits[i], NULL) # does by reference
for (hit in hits) setattr(attrs, hit, NULL) # does by reference

Comment thread R/data.table.R
Comment on lines +638 to +641
if (.dt_is_nrows(jsub)) { # 5403 unwrap multicolumn jvals for gfunctions that can return lists
jvals = if (length(jvals) != length(lhs)) split(unlist(jvals), rep(seq_along(jvals[[1L]]), length(jvals))) else lapply(jvals, unlist)
}
jvals

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's leverage early returns to unnest this for clarity

Suggested change
if (.dt_is_nrows(jsub)) { # 5403 unwrap multicolumn jvals for gfunctions that can return lists
jvals = if (length(jvals) != length(lhs)) split(unlist(jvals), rep(seq_along(jvals[[1L]]), length(jvals))) else lapply(jvals, unlist)
}
jvals
if (!.dt_is_nrows(jsub)) return(jvals) # 5403 unwrap multicolumn jvals for gfunctions that can return lists
if (length(jvals) == length(lhs))
return(lapply(jvals, unlist))
split(unlist(jvals), rep(seq_along(jvals[[1L]]), length(jvals)))

Comment thread R/data.table.R
.dt_group_rows = function(f__, len__, o__, irows) {
rows = vecseq(f__,len__,NULL)
if (length(o__)) rows = o__[rows]
if (length(irows)) rows = irows[rows]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (length(irows)) rows = irows[rows]
if (length(irows)) return(irows[rows])

This branch has not been deployed

No deployments
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.

2 participants