From 85bacc793d33c628841f5fc8fd8f8992092aa80e Mon Sep 17 00:00:00 2001 From: Matt Dowle Date: Tue, 29 Nov 2016 01:12:10 -0800 Subject: [PATCH] Fixed the other 2 errors on Solaris related to tzone attribute from as.POSIXct vs as.POSIXlt, I guess and hope. Closes #1934. Improved test()'s output in case it is not that. --- NEWS.md | 4 ++++ R/test.data.table.R | 15 ++++++++++++--- inst/tests/tests.Rraw | 12 ++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 31e417645..002995d3e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,10 +7,14 @@ 1. `fwrite(..., quote='auto')` already quoted a field if it contained a `sep` or `\n`, or `sep2[2]` when `list` columns are present. Now it also quotes a field if it contains a double quote (`"`) as documented, [#1925](https://github.com/Rdatatable/data.table/issues/1925). Thanks to Aki Matsuo for reporting. Tests added. The `qmethod` tests did test escaping embedded double quotes, but only when `sep` or `\n` was present in the field as well to trigger the quoting of the field. +2. Fixed 3 test failures on Solaris only, [#1934](https://github.com/Rdatatable/data.table/issues/1934). Two were on both sparc and x86 and related to a `tzone` attribute difference between `as.POSIXct` and `as.POSIXlt` even when passed the default `tz=""`. The third was on sparc only: a minor rounding issue in `fwrite()` of 1e-305. + #### NOTES 1. It seems OpenMP is not available on CRAN's Mac platform; NOTEs have appeared in [CRAN checks](https://cran.r-project.org/web/checks/check_results_data.table.html). Moved `Rprintf` from `init.c` to `packageStartupMessage` to avoid the NOTE as requested urgently by Professor Ripley. Also fixed the bad grammar of the message: 'single threaded' now 'single-threaded'. If you have a Mac and run macOS or OS X on it (I run Ubuntu on mine) please contact CRAN maintainers and/or Apple if you'd like CRAN's Mac binary to support OpenMP. Otherwise, please follow [these instructions](https://github.com/Rdatatable/data.table/wiki/Installation) which people have reported work well using OpenMP on a Mac. +2. There are now 5,910 raw tests as reported by `test.data.table()`. Tests cover 91% of the 4k lines of R and 89% of the 7k lines of C. Any help creating tests to hit the missed lines shown [here](https://codecov.io/github/Rdatatable/data.table?branch=master) would be greatly appreciated. + ### Changes in v1.9.8 (on CRAN 25 Nov 2016) diff --git a/R/test.data.table.R b/R/test.data.table.R index 4bbea3b94..e8db21b40 100644 --- a/R/test.data.table.R +++ b/R/test.data.table.R @@ -45,10 +45,16 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE) { # .devtesting = TRUE compactprint <- function(DT, topn=2) { - cn = paste(" [Key=",paste(key(DT),collapse=",")," Types=",paste(substring(gsub("integer64","i64",sapply(DT,class)),1,3),collapse=","),"]",sep="") + tt = sapply(DT,function(x)class(x)[1L]) + tt[tt=="integer64"] = "i64" + cn = paste(" [Key=",paste(key(DT),collapse=","), + " Types=",paste(substring(sapply(DT,typeof),1,3),collapse=","), + " Classes=",paste(substring(tt,1,3),collapse=","), + "]",sep="") print(copy(DT)[,(cn):=""], topn=topn) invisible() } + test <- function(num,x,y,error=NULL,warning=NULL,output=NULL) { # Usage: # i) tests that x equals y when both x and y are supplied, the most common usage @@ -66,6 +72,7 @@ test <- function(num,x,y,error=NULL,warning=NULL,output=NULL) { # 3) each test has a unique id which we refer to in commit messages, emails etc. nfail = get("nfail", parent.frame()) # to cater for both test.data.table() and stepping through tests in dev whichfail = get("whichfail", parent.frame()) + all.equal.result = TRUE assign("ntest", get("ntest", parent.frame()) + 1, parent.frame(), inherits=TRUE) # bump number of tests run assign("lastnum", num, parent.frame(), inherits=TRUE) v = getOption("datatable.verbose") @@ -155,7 +162,7 @@ test <- function(num,x,y,error=NULL,warning=NULL,output=NULL) { setattr(xc,"index",NULL) # too onerous to create test RHS with the correct index as well, just check result setattr(yc,"index",NULL) if (identical(xc,yc) && identical(key(x),key(y))) return() # check key on original x and y because := above might have cleared it on xc or yc - if (isTRUE(all.equal(xc,yc)) && identical(key(x),key(y)) && + if (isTRUE(all.equal.result<-all.equal(xc,yc)) && identical(key(x),key(y)) && identical(sapply(xc,typeof), sapply(yc,typeof))) return() } if (is.factor(x) && is.factor(y)) { @@ -163,13 +170,15 @@ test <- function(num,x,y,error=NULL,warning=NULL,output=NULL) { y = factor(y) if (identical(x,y)) return() } - if (is.atomic(x) && is.atomic(y) && isTRUE(all.equal(x,y))) return() # For test 617 on r-prerel-solaris-sparc on 7 Mar 2013 + if (is.atomic(x) && is.atomic(y) && isTRUE(all.equal.result<-all.equal(x,y))) return() + # For test 617 on r-prerel-solaris-sparc on 7 Mar 2013 } cat("Test",num,"ran without errors but failed check that x equals y:\n") cat("> x =",deparse(xsub),"\n") if (is.data.table(x)) compactprint(x) else if (length(x)>6) {cat("First 6 of", length(x),":");print(head(x))} else print(x) cat("> y =",deparse(ysub),"\n") if (is.data.table(y)) compactprint(y) else if (length(y)>6) {cat("First 6 of", length(y),":");print(head(y))} else print(y) + if (!isTRUE(all.equal.result)) cat(all.equal.result,sep="\n") assign("nfail", nfail+1, parent.frame(), inherits=TRUE) assign("whichfail", c(whichfail, num), parent.frame(), inherits=TRUE) invisible() diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 0d053c849..16e0650ad 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -7497,11 +7497,15 @@ test(1611.1, as.data.table(l1), setnames(setDT(as.data.frame(l1)), c("a", paste( test(1611.2, as.data.table(l2), setnames(setDT(as.data.frame(l2)), c("V1", "V1.1", paste("V", 2:5, sep="")))) # fix for #646 -ll = list(a=as.POSIXlt("2015-01-01"), b=1:5) -test(1612.1, as.data.table(ll), data.table(a=as.POSIXct("2015-01-01"), b=1:5), warning="POSIXlt column type detected") +# tz= is explicitly specified otherwise CRAN's solaris (both sparc and x86) fail. It may not be solaris per se +# but something related to the timezone of the two solaris machines. I guess one or the other of as.POSIXct or +# as.POSIXlt create the 'tzone' attribute differently for default tz="", just on solaris. I checked test.data.table +# already uses all.equal(), not identical(). So I don't think it is an accuracy problem. But could be wrong. +ll = list(a=as.POSIXlt("2015-01-01", tz='UTC'), b=1:5) +test(1612.1, as.data.table(ll), data.table(a=as.POSIXct("2015-01-01", tz='UTC'), b=1:5), warning="POSIXlt column type detected") dt = data.table(d1="1984-03-17") -ans = data.table(d1="1984-03-17", d2=as.POSIXct("1984-03-17")) -test(1612.2, dt[, d2 := strptime(d1, "%Y-%m-%d")], ans, warning="POSIXlt column type detected and converted") +ans = data.table(d1="1984-03-17", d2=as.POSIXct("1984-03-17", tz='UTC')) +test(1612.2, dt[, d2 := strptime(d1, "%Y-%m-%d", tz='UTC')], ans, warning="POSIXlt column type detected and converted") ll = list(a=as.POSIXlt("2015-01-01"), b=2L) test(1612.3, setDT(ll), error="Column 1 is of POSIXlt type")