Repository navigation
move grouped results into helpers out of [ - #7943
ben-schwen wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
e8f6638 to
2155098
Compare
(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
|
No behaviour change.
2155098 to
6f04972
Compare
| 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) |
There was a problem hiding this comment.
move setattr() out of the branch?
| 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) |
| 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) |
There was a problem hiding this comment.
Possibly cleaner flow:
| 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) | |
| } |
| 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") |
There was a problem hiding this comment.
| 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()} |
| 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 |
There was a problem hiding this comment.
| 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 |
| 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 |
There was a problem hiding this comment.
Let's leverage early returns to unnest this for clarity
| 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))) |
| .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] |
There was a problem hiding this comment.
| if (length(irows)) rows = irows[rows] | |
| if (length(irows)) return(irows[rows]) |
Towards #852