@@ -17938,31 +17938,31 @@ for (f1 in funs) {
1793817938 DT = data.table(x=f1(1:4), g=g)
1793917939 for (f2 in funs) {
1794017940 testnum = testnum + 1L
17941- test(2218.0 + testnum*0.001, DT[, shift(x)], f1(c(NA, 1:3)))
17941+ test(2218.0 + testnum*0.001, DT[, shift(x)], f1(c(NA, 1:3)), context=sprintf("f1=%s, f2=%s, ungrouped, no fill", deparse(f1), deparse(f2 )))
1794217942 testnum = testnum + 1L
17943- w = if (identical(f2,as.character) && !identical(f1,as.character)) "Coercing.*character.*to match the type of target vector"
17944- test(2218.0 + testnum*0.001, DT[, shift(x, fill=f2(NA))], f1(c(NA, 1:3)), warning=w)
17943+ w = if (identical(f2, as.character) && !identical(f1, as.character)) "Coercing.*character.*to match the type of target vector"
17944+ test(2218.0 + testnum*0.001, DT[, shift(x, fill=f2(NA))], f1(c(NA, 1:3)), warning=w, context=sprintf("f1=%s, f2=%s, ungrouped, fill=NA", deparse(f1), deparse(f2)) )
1794517945 testnum = testnum + 1L
17946- if (identical(f1,as.character) && identical(f2,as.complex)) {
17946+ if (identical(f1, as.character) && identical(f2, as.complex)) {
1794717947 # one special case due to as.complex(0)=="0+0i"!="0"
17948- test(2218.0 + testnum*0.001, DT[, shift(x, fill="0")], f1(0:3))
17948+ test(2218.0 + testnum*0.001, DT[, shift(x, fill="0")], f1(0:3), context="f1=as.character, f2=as.complex, ungrouped" )
1794917949 } else {
17950- test(2218.0 + testnum*0.001, DT[, shift(x, fill=f2(0))], f1(0:3), warning=w)
17950+ test(2218.0 + testnum*0.001, DT[, shift(x, fill=f2(0))], f1(0:3), warning=w, context=sprintf("f1=%s, f2=%s, ungrouped, fill=0", deparse(f1), deparse(f2)) )
1795117951 }
1795217952
1795317953 testnum = testnum + 1L
17954- test(2218.0 + testnum*0.001, DT[, shift(x), by=g], data.table(g=g, V1=f1(c(NA, 1, NA, 3))))
17954+ test(2218.0 + testnum*0.001, DT[, shift(x), by=g], data.table(g=g, V1=f1(c(NA, 1, NA, 3))), context=sprintf("f1=%s, f2=%s, grouped, no fill", deparse(f1), deparse(f2 )))
1795517955 testnum = testnum + 1L
1795617956 w = if (identical(f2,as.character) && !identical(f1,as.character)) "Coercing.*character.*to match the type of target vector"
1795717957 f = f2(NA)
17958- test(2218.0 + testnum*0.001, DT[, shift(x, fill=f), by=g], data.table(g=g, V1=f1(c(NA, 1, NA, 3))), warning=w)
17958+ test(2218.0 + testnum*0.001, DT[, shift(x, fill=f), by=g], data.table(g=g, V1=f1(c(NA, 1, NA, 3))), warning=w, context=sprintf("f1=%s, f2=%s, grouped, fill=NA", deparse(f1), deparse(f2)) )
1795917959 testnum = testnum + 1L
17960- if (identical(f1,as.character) && identical(f2,as.complex)) {
17960+ if (identical(f1, as.character) && identical(f2, as.complex)) {
1796117961 # one special case due to as.complex(0)=="0+0i"!="0"
17962- test(2218.0 + testnum*0.001, DT[, shift(x, fill="0"), by=g], data.table(g=g, V1=f1(c(0,1,0,3))))
17962+ test(2218.0 + testnum*0.001, DT[, shift(x, fill="0"), by=g], data.table(g=g, V1=f1(c(0,1,0,3))), context="f1=as.character, f2=as.complex, grouped" )
1796317963 } else {
1796417964 f = f2(0)
17965- test(2218.0 + testnum*0.001, DT[, shift(x, fill=f), by=g], data.table(g=g, V1=f1(c(0,1,0,3))), warning=w)
17965+ test(2218.0 + testnum*0.001, DT[, shift(x, fill=f), by=g], data.table(g=g, V1=f1(c(0,1,0,3))), warning=w, context=sprintf("f1=%s, f2=%s, grouped, fill=0", deparse(f1), deparse(f2)) )
1796617966 }
1796717967 }
1796817968}
@@ -17979,9 +17979,9 @@ funs = c("sum", "mean", "min", "max", "median", "var", "sd", "prod")
1797917979testnum = 0L
1798017980for (fun in funs) {
1798117981 testnum = testnum + 1L
17982- test(2220.0 + testnum*0.01, EVAL("DT[,",fun,"(i, na.rm='a'), g]"), error="na.rm must be TRUE or FALSE")
17982+ test(2220.0 + testnum*0.01, EVAL("DT[,",fun,"(i, na.rm='a'), g]"), error="na.rm must be TRUE or FALSE", context=sprintf("fun=%s [na.rm='a']", fun) )
1798317983 testnum = testnum + 1L
17984- test(2220.0 + testnum*0.01, EVAL("DT[,",fun,"(f), g]"), error=sprintf("%s is not meaningful for factors.", fun))
17984+ test(2220.0 + testnum*0.01, EVAL("DT[,",fun,"(f), g]"), error=sprintf("%s is not meaningful for factors.", fun), context=sprintf("fun=%s [factor]", fun) )
1798517985}
1798617986testnum = testnum + 1L
1798717987test(2220.0 + testnum*0.01, DT[, prod(l), g], error="GForce prod can only be applied to columns, not .SD or similar.")
@@ -18018,13 +18018,14 @@ if (test_bit64) {
1801818018}
1801918019i = 1L
1802018020for (col in names(DT)[-1]) {
18021- for (n in list(1, 5, -1, -5, c(1,2), c(-1,1))) {
18022- for (type in c('lag','lead','shift','cyclic')) {
18021+ for (n in list(1, 5, -1, -5, c(1, 2), c(-1, 1))) {
18022+ for (type in c('lag', 'lead', 'shift', 'cyclic')) {
1802318023 # fill is tested by group in tests 2218.*; see comments in #5205
1802418024 # sapply(sapply()) changed to for(for(for())) to save 29MiB, #5517
1802518025 test(2224.1+i/10000, # 192 tests here when test_bit64=TRUE; 168 when FALSE
1802618026 EVAL(sprintf("DT[, shift(%s, %d, type='%s'), by=x]$V1", col, n, type)),
18027- ans[[i]])
18027+ ans[[i]],
18028+ context=sprintf("col=%s, n=%s", type=%s", col, paste(n, collapse=","), type))
1802818029 i = i+1L
1802918030 }
1803018031 }
@@ -18283,18 +18284,18 @@ test(2233.38, copy(DT)[, val:=v[1L], keyby=.(A,B), verbose=TRUE], data.table(A=I
1828318284set.seed(10)
1828418285n = 100
1828518286a = data.table(id1=1:n, id2=sample(1:900,n,replace=TRUE), flag=sample(c(0,0,0,1),n,replace=TRUE))
18286- for (opt in c(0,Inf)) {
18287+ for (opt in c(0, Inf)) {
1828718288 options(datatable.optimize=opt)
1828818289 out = if (opt) "GForce.*gsum" else "GForce FALSE"
1828918290 B = copy(a)
1829018291 A = a[sample(seq_len(nrow(a)), nrow(a))] # shuffle
1829118292 num_bump = (opt>0)/100
18292- test(2233.39+num_bump+0.001, A[, t1 := sum(flag, na.rm=TRUE), by=id2, verbose=TRUE], A, output=out) # y=A dummy just to test output=
18293+ test(2233.39+num_bump+0.001, A[, t1 := sum(flag, na.rm=TRUE), by=id2, verbose=TRUE], A, output=out, context=sprintf("optimize=%s [I]", format(opt)) ) # y=A dummy just to test output=
1829318294 setorder(A, id1)
18294- test(2233.39+num_bump+0.002, A[, t2 := sum(flag, na.rm=TRUE), by=id2, verbose=TRUE], A, output=out)
18295- test(2233.39+num_bump+0.003, any(A[,t1!=t2]), FALSE )
18296- test(2233.39+num_bump+0.004, any(A[, length(unique(t1))>1, by=id2]$V1), FALSE )
18297- test(2233.39+num_bump+0.005, any(A[, length(unique(t2))>1, by=id2]$V1), FALSE )
18295+ test(2233.39+num_bump+0.002, A[, t2 := sum(flag, na.rm=TRUE), by=id2, verbose=TRUE], A, output=out, context=sprintf("optimize=%s [II]", format(opt)) )
18296+ test(2233.39+num_bump+0.003, ! any(A[,t1!=t2]))
18297+ test(2233.39+num_bump+0.004, ! any(A[, length(unique(t1))>1, by=id2]$V1), context=sprintf("optimize=%s [III]", format(opt)) )
18298+ test(2233.39+num_bump+0.005, ! any(A[, length(unique(t2))>1, by=id2]$V1), context=sprintf("optimize=%s [IV]", format(opt)) )
1829818299}
1829918300# test from #5337
1830018301n=4; k=2
@@ -19283,61 +19284,80 @@ names(sdlist) <- sdnames
1928319284for (opt in c(0, 1, 2)) {
1928419285 test(2283 + opt/10 + 0.001, options=c(datatable.optimize=opt),
1928519286 names(M[, c(m=lapply(.SD, mean)), by="cyl"]),
19286- c("cyl", names(c(m=sdlist))))
19287+ c("cyl", names(c(m=sdlist))),
19288+ context=sprintf("optimize=%s [I]", format(opt)))
1928719289 test(2283 + opt/10 + 0.002, options=c(datatable.optimize=opt),
1928819290 names(M[, c(Mpg=list(mpg), lapply(.SD, mean)), by="cyl"]),
19289- c("cyl", "Mpg", sdnames))
19291+ c("cyl", "Mpg", sdnames),
19292+ context=sprintf("optimize=%s [II]", format(opt)))
1929019293 test(2283 + opt/10 + 0.003, options=c(datatable.optimize=opt),
1929119294 names(M[, c(Mpg=list(mpg), m=lapply(.SD, mean)), by="cyl"]),
19292- c("cyl", "Mpg", names(c(m=sdlist))))
19295+ c("cyl", "Mpg", names(c(m=sdlist))),
19296+ context=sprintf("optimize=%s [III]", format(opt)))
1929319297 test(2283 + opt/10 + 0.004, options=c(datatable.optimize=opt),
1929419298 names(M[, c(mpg=list(mpg), mpg=lapply(.SD, mean)), by="cyl"]),
19295- c("cyl", "mpg", names(c(mpg=sdlist))))
19299+ c("cyl", "mpg", names(c(mpg=sdlist))),
19300+ context=sprintf("optimize=%s [IV]", format(opt)))
1929619301 test(2283 + opt/10 + 0.005, options=c(datatable.optimize=opt),
1929719302 names(M[, c(list(mpg), lapply(.SD, mean)), by="cyl"]),
19298- c("cyl", "V1", sdnames))
19303+ c("cyl", "V1", sdnames),
19304+ context=sprintf("optimize=%s [V]", format(opt)))
1929919305 test(2283 + opt/10 + 0.006, options=c(datatable.optimize=opt),
1930019306 names(M[, c(lapply(.SD, mean), list(mpg)), by="cyl"]),
19301- c("cyl", sdnames, sprintf("V%d", length(sdnames)+1L)))
19307+ c("cyl", sdnames, sprintf("V%d", length(sdnames)+1L)),
19308+ context=sprintf("optimize=%s [VI]", format(opt)))
1930219309 test(2283 + opt/10 + 0.007, options=c(datatable.optimize=opt),
1930319310 names(M[, c(lapply(.SD, mean), lapply(.SD, sum)), by="cyl"]),
19304- c("cyl", sdnames, sdnames))
19311+ c("cyl", sdnames, sdnames),
19312+ context=sprintf("optimize=%s [VII]", format(opt)))
1930519313 test(2283 + opt/10 + 0.008, options=c(datatable.optimize=opt),
1930619314 names(M[, c(mean=lapply(.SD, mean), sum=lapply(.SD, sum)), by="cyl"]),
19307- c("cyl", names(c(mean=sdlist, sum=sdlist))))
19315+ c("cyl", names(c(mean=sdlist, sum=sdlist))),
19316+ context=sprintf("optimize=%s [VIII]", format(opt)))
1930819317 test(2283 + opt/10 + 0.009, options=c(datatable.optimize=opt),
1930919318 names(M[, c(lapply(.SD, mean), sum=lapply(.SD, sum)), by="cyl"]),
19310- c("cyl", sdnames, names(c(sum=sdlist))) )
19319+ c("cyl", sdnames, names(c(sum=sdlist))) ,
19320+ context=sprintf("optimize=%s [IX]", format(opt)))
1931119321 test(2283 + opt/10 + 0.010, options=c(datatable.optimize=opt),
1931219322 names(M[, c(" "=lapply(.SD, mean), "."=lapply(.SD, sum)), by="cyl"]),
19313- c("cyl", names(c(" "=sdlist, "."=sdlist))))
19323+ c("cyl", names(c(" "=sdlist, "."=sdlist))),
19324+ context=sprintf("optimize=%s [X]", format(opt)))
1931419325 test(2283 + opt/10 + 0.011, options=c(datatable.optimize=opt),
1931519326 names(M[, c(A=list(a=mpg, b=hp), lapply(.SD, mean)), by="cyl"]),
19316- c("cyl", names(c(A=list(a=0, b=0))), sdnames))
19327+ c("cyl", names(c(A=list(a=0, b=0))), sdnames),
19328+ context=sprintf("optimize=%s [XI]", format(opt)))
1931719329 test(2283 + opt/10 + 0.012, options=c(datatable.optimize=opt),
1931819330 names(M[, c(A=list(mpg, hp), lapply(.SD, mean)), by="cyl"]),
19319- c("cyl", names(c(A=list(0, 0))), sdnames))
19331+ c("cyl", names(c(A=list(0, 0))), sdnames),
19332+ context=sprintf("optimize=%s [XII]", format(opt)))
1932019333 test(2283 + opt/10 + 0.013, options=c(datatable.optimize=opt),
1932119334 names(M[, c(A=list(mpg, b=hp, wt), lapply(.SD, mean)), by="cyl"]),
19322- c("cyl", names(c(A=list(0, b=0, 0))), sdnames))
19335+ c("cyl", names(c(A=list(0, b=0, 0))), sdnames),
19336+ context=sprintf("optimize=%s [XIII]", format(opt)))
1932319337 test(2283 + opt/10 + 0.014, options=c(datatable.optimize=opt),
1932419338 names(M[, c(A=list(mpg), lapply(.SD, mean)), by="cyl"]),
19325- c("cyl", names(c(A=list(0))), sdnames))
19339+ c("cyl", names(c(A=list(0))), sdnames),
19340+ context=sprintf("optimize=%s [XIV]", format(opt)))
1932619341 test(2283 + opt/10 + 0.015, options=c(datatable.optimize=opt),
1932719342 names(M[, c(" "=list(" "=hp, "."=disp, mpg), lapply(.SD, mean)), by="cyl"]),
19328- c("cyl", names(c(" "=list(" "=0, "."=0, 0))), sdnames))
19343+ c("cyl", names(c(" "=list(" "=0, "."=0, 0))), sdnames),
19344+ context=sprintf("optimize=%s [XV]", format(opt)))
1932919345 test(2283 + opt/10 + 0.016, options=c(datatable.optimize=opt),
1933019346 names(M[, c("."=list(" "=hp, "."=disp, mpg), lapply(.SD, mean)), by="cyl"]),
19331- c("cyl", names(c("."=list(" "=0, "."=0, 0))), sdnames))
19347+ c("cyl", names(c("."=list(" "=0, "."=0, 0))), sdnames),
19348+ context=sprintf("optimize=%s [XVI]", format(opt)))
1933219349 test(2283 + opt/10 + 0.017, options=c(datatable.optimize=opt),
1933319350 names(M[, c(list(mpg, b=hp), lapply(.SD, mean)), by="cyl", .SDcols=c("vs", "am")]),
19334- c("cyl", "V1", "b", "vs", "am"))
19351+ c("cyl", "V1", "b", "vs", "am"),
19352+ context=sprintf("optimize=%s [XVII]", format(opt)))
1933519353 test(2283 + opt/10 + 0.018, options=c(datatable.optimize=opt),
1933619354 names(M[, c(list(mpg, b=hp), c(lapply(.SD, mean))), by="cyl", .SDcols=c("vs", "am")]),
19337- c("cyl", "V1", "b", "vs", "am"))
19355+ c("cyl", "V1", "b", "vs", "am"),
19356+ context=sprintf("optimize=%s [XVIII]", format(opt)))
1933819357 test(2283 + opt/10 + 0.019, options=c(datatable.optimize=opt),
1933919358 names(M[, c(mpg[1], list(mpg, b=hp), c(lapply(.SD, mean))), by="cyl", .SDcols=c("vs", "am")]),
19340- c("cyl", "V1", "V2", "b", "vs", "am"))
19359+ c("cyl", "V1", "V2", "b", "vs", "am"),
19360+ context=sprintf("optimize=%s [XIX]", format(opt)))
1934119361}
1934219362
1934319363# Confusing behavior with DT[, min(var):max(var)] #2069
0 commit comments