Skip to content

Commit

Permalink
Fixed the other 2 errors on Solaris related to tzone attribute from a…
Browse files Browse the repository at this point in the history
…s.POSIXct vs as.POSIXlt, I guess and hope. Closes #1934. Improved test()'s output in case it is not that.
  • Loading branch information
mattdowle committed Nov 29, 2016
1 parent e75e71f commit 85bacc7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 12 additions & 3 deletions R/test.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -155,21 +162,23 @@ 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)) {
x = factor(x)
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()
Expand Down
12 changes: 8 additions & 4 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 85bacc7

Please sign in to comment.