Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace unnecessary calls to getNumericRounding() in tests.Rraw where possible #6119

Merged
merged 3 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -1247,15 +1247,14 @@ test(388, DT[,{ans = score[1]

# Test unique.data.table for numeric columns within tolerance, for consistency with
# with unique.data.frame which does this using paste.
old_rounding = getNumericRounding()
DT = data.table(a=tan(pi*(1/4 + 1:10)),b=42L)
# tan(...) from example in ?all.equal.
test(395, all.equal(DT$a, rep(1,10)))
test(396, length(unique(DT$a))>1) # 10 unique values on all CRAN machines (as of Nov 2011) other than mac (5 unique)
# commenting these two as they give different results on os x and linux.
# test(397.1, unique(DT), DT[duplicated(DT)]) # default, no rounding
# test(398.1, duplicated(DT), c(FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE))
setNumericRounding(2L)
old_rounding = setNumericRounding(2L)
test(397.2, unique(DT), DT[1]) # before v1.7.2 unique would return all 10 rows. For stability within tolerance, data.table has its own modified numeric sort.
test(398.2, duplicated(DT), c(FALSE,rep(TRUE,9)))
setNumericRounding(old_rounding)
Expand Down Expand Up @@ -4084,13 +4083,12 @@ test(1146.3, set(DF, i=NULL, j="bla", value=seq_len(nrow(DF))), error="set() on
if (test_longdouble) {
# e.g. not on CRAN's solaris-sparc 32bit, and not under valgrind which uses 53 instead of 64 longdouble.digits

old = getNumericRounding()

set.seed(6)
x = rnorm(1e4)*1e4 # first 1e4 reduced from 1e6 to save ram, #5517
x = c(x, 11969.235757385, 11969.235757322) # add back 2 numbers from the 1e6 sample whose order is changed in test 1147.3
ans = base::sort.list(x, method="shell")
setNumericRounding(0)
old = setNumericRounding(0)
test(1147.1, ans, forderv(x))
setNumericRounding(1)
test(1147.2, ans, forderv(x))
Expand Down Expand Up @@ -4385,10 +4383,9 @@ test(1194, DT[.(x),.N], 1L) # tests bmerge uses twiddle
DT[3, val:=0.0275016249291963]
setkey(DT, NULL) # val[3] and val[4] are now equal, within 2 byte rounding
test(1195, DT[,.N,keyby=val], setkey(DT,val)[,.N,by=val])
old_rounding = getNumericRounding() # default is 0
test(1196.1, DT[,.N,by=val]$N, INT(1,1,1,1))
test(1196.2, DT[.(x),.N], 1L)
setNumericRounding(2L)
old_rounding = setNumericRounding(2L) # default is 0
test(1197.1, DT[,.N,by=val]$N, INT(1,1,2))
test(1197.2, DT[.(x),.N], 2L)
setNumericRounding(old_rounding)
Expand Down Expand Up @@ -4790,11 +4787,10 @@ ans = NULL
if (nfail > oldnfail) cat(seedInfo, "\n") # to reproduce

###############
old_rounding = getNumericRounding()
# turning off tolerance for UPCs (> 11 s.f. stored in numeric), #342
DT <- data.table(upc = c(301426027592, 301426027593, 314775802939, 314775802940, 314775803490, 314775803491, 314775815510, 314775815511, 314933000171, 314933000172),
year = 2006:2007)
setNumericRounding(2L)
old_rounding = setNumericRounding(2L)
test(1253, DT[,.N,by=upc]$N, rep.int(2L,5L))
setNumericRounding(0)
test(1254, DT[,.N,by=upc], data.table(upc=DT$upc, N=1L))
Expand Down Expand Up @@ -4882,9 +4878,8 @@ test(1268.22, dt[, c(as.list(c), lapply(.SD, mean)), by=a],
### FR #2722 tests end here ###

# Wide range numeric and integer64, to test all bits
old_rounding = getNumericRounding()
old_rounding = setNumericRounding(0)
x = sample( c(seq(-1e100, 1e100, length.out=1e3), c(seq(-1e-100,1e-100,length.out=1e3))) ) # 1e5 reduced to 1e3, #5517
setNumericRounding(0)
test(1269, forderv(x), base::order(x))
setNumericRounding(2) # not affected by rounding
test(1270, forderv(x), base::order(x))
Expand Down Expand Up @@ -4920,15 +4915,14 @@ setNumericRounding(old_rounding)

# rounding of milliseconds, workaround, TO DO: #485
# http://stackoverflow.com/questions/22356957/rounding-milliseconds-of-posixct-in-data-table-v1-9-2-ok-in-1-8-10
old_rounding = getNumericRounding()
old_rounding = setNumericRounding(2)
DT = data.table(timestamp=as.POSIXct(
c("2013-01-01 17:51:00.707",
"2013-01-01 17:51:59.996",
"2013-01-01 17:52:00.059",
"2013-01-01 17:54:23.901",
"2013-01-01 17:54:23.913",
"2013-01-01 17:54:23.914")))
setNumericRounding(2)
test(1279, duplicated(DT), rep(c(FALSE,TRUE), c(4,2)))
setNumericRounding(1)
test(1280, duplicated(DT), rep(FALSE, 6))
Expand Down Expand Up @@ -13137,8 +13131,7 @@ test(1942.02, DT[,sum(v),keyby=id1,verbose=TRUE], data.table(id1=c("D","A","C"),
setindex(DT,id2)
test(1942.03, DT[,sum(v),keyby=id2,verbose=TRUE], data.table(id2=INT(3,9,2), V1=INT(6,6,3), key="id2"), output="Finding groups using uniqlist on index 'id2")
setindex(DT,id3)
oldnr = getNumericRounding() # TODO: return old
setNumericRounding(0)
oldnr = setNumericRounding(0)
MichaelChirico marked this conversation as resolved.
Show resolved Hide resolved
test(1942.04, DT[,sum(v),keyby=id3,verbose=TRUE], data.table(id3=c(3.4, 9.1, 3.3), V1=INT(4,7,4), key="id3"), output="Finding groups using uniqlist on index 'id3'")
setNumericRounding(1)
test(1942.05, DT[,sum(v),keyby=id3,verbose=TRUE], data.table(id3=c(3.4, 9.1, 3.3), V1=INT(4,7,4), key="id3"), output="Finding groups using uniqlist on index 'id3'")
Expand Down
Loading