Skip to content

Commit 9875906

Browse files
Only print progress if more than one group (#6693)
* only print progress if ngrp>1 * Add NEWS entry --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 3b2812b commit 9875906

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ rowwiseDT(
139139

140140
7. The `dcast()` and `melt()` generics no longer attempt to redirect to {reshape2} methods when passed non-`data.table`s. If you're still using {reshape2}, you must use namespace-qualification: `reshape2::dcast()`, `reshape2::melt()`. We have been warning about the deprecation since v1.12.4 (2019). Please note that {reshape2} is retired.
141141
142+
8. `showProgress` in `[` is disabled for "trivial" grouping (`.NGRP==1L`), [#6668](https://github.com/Rdatatable/data.table/issues/6668). Thanks @MichaelChirico for the request and @joshhwuu for the PR.
143+
142144
# data.table [v1.16.2](https://github.com/Rdatatable/data.table/milestone/35) (9 October 2024)
143145
144146
## BUG FIXES

src/dogroups.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
7070
SEXP ans=NULL, jval, thiscol, BY, N, I, GRP, iSD, xSD, rownames, s, RHS, target, source;
7171
Rboolean wasvector, firstalloc=FALSE, NullWarnDone=FALSE;
7272
const bool verbose = LOGICAL(verboseArg)[0]==1;
73-
const bool showProgress = LOGICAL(showProgressArg)[0]==1;
7473
double tstart=0, tblock[10]={0}; int nblock[10]={0}; // For verbose printing, tstart is updated each block
75-
double startTime = (showProgress) ? wallclock() : 0; // For progress printing, startTime is set at the beginning
76-
double nextTime = (showProgress) ? startTime+3 : 0; // wait 3 seconds before printing progress
7774
bool hasPrinted = false;
7875

7976
if (!isInteger(order)) internal_error(__func__, "order not integer vector"); // # nocov
@@ -89,6 +86,10 @@ SEXP dogroups(SEXP dt, SEXP dtcols, SEXP groups, SEXP grpcols, SEXP jiscols, SEX
8986
// fix for longstanding FR/bug, #495. E.g., DT[, c(sum(v1), lapply(.SD, mean)), by=grp, .SDcols=v2:v3] resulted in error.. the idea is, 1) we create .SDall, which is normally == .SD. But if extra vars are detected in jexp other than .SD, then .SD becomes a shallow copy of .SDall with only .SDcols in .SD. Since internally, we don't make a copy, changing .SDall will reflect in .SD. Hopefully this'll workout :-).
9087
SEXP SDall = PROTECT(findVar(install(".SDall"), env)); nprotect++; // PROTECT for rchk
9188
SEXP SD = PROTECT(findVar(install(".SD"), env)); nprotect++;
89+
90+
const bool showProgress = LOGICAL(showProgressArg)[0]==1 && ngrp > 1; // showProgress only if more than 1 group
91+
double startTime = (showProgress) ? wallclock() : 0; // For progress printing, startTime is set at the beginning
92+
double nextTime = (showProgress) ? startTime+3 : 0; // wait 3 seconds before printing progress
9293

9394
defineVar(sym_BY, BY = PROTECT(allocVector(VECSXP, ngrpcols)), env); nprotect++; // PROTECT for rchk
9495
SEXP bynames = PROTECT(allocVector(STRSXP, ngrpcols)); nprotect++; // TO DO: do we really need bynames, can we assign names afterwards in one step?

0 commit comments

Comments
 (0)