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

Add errors on separate lines for coverage #4301

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 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
8 changes: 8 additions & 0 deletions .dev/CRAN_Release.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ grep -nE "(llu|lld|zd|zu)" src/*.[hc]
grep -P "\t" ./R/*.R
grep -P "\t" ./src/*.c

# all error branches should be on a new line to be properly included in codecov; exceptions:
# (1) in a comment (pattern: after // or after \s*[*]
# (2) in '} else error(' pattern (if else is covered, so is the error)
# (3) in #define macros
for type in error warning STOP DTWARN Error; do
grep -Enr "\b$type[(]" src --include=*.c | grep -Ev "^src\/[a-zA-Z-]+[.]c:[0-9]+:\s*(?:(?:[}]?\s*else\s*)?$type|#define|[*]|.*\/\/.*$type)"
done

# No T or F symbols in tests.Rraw. 24 valid F (quoted, column name or in data) and 1 valid T at the time of writing
grep -n "[^A-Za-z0-9]T[^A-Za-z0-9]" ./inst/tests/tests.Rraw
grep -n "[^A-Za-z0-9]F[^A-Za-z0-9]" ./inst/tests/tests.Rraw
Expand Down
76 changes: 73 additions & 3 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
test = data.table:::test
uniqlengths = data.table:::uniqlengths
uniqlist = data.table:::uniqlist
veqseq = data.table:::vecseq
which_ = data.table:::which_
which.first = data.table:::which.first
which.last = data.table:::which.last
Expand Down Expand Up @@ -6312,15 +6313,13 @@ options(datatable.optimize = Inf)

# fread dec=',' e.g. France
test(1439, fread("A;B\n1;2,34\n", dec="12"), error="nchar(dec) == 1L is not TRUE")
test(1440, fread("A;B\n8;2,34\n", dec="1"), data.table(A=8L, B="2,34"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!dec %chin% c('.', ',') is implied incorrect by L1179 of fread.c @ master:

dec='' not allowed. Should be '.' or ','

?fread is not as strict:

The decimal separator as in utils::read.csv. If not "." (default) then usually ",". See details.

Took a conservative approach for now, and blocked !dec %chin% c(',', '.'). But that broke two tests (1440 and 1444.2 here).

dec='1' and dec='*' ran without errors... happy to restore this to work, and change the error/message found in fread.c.

test(1441, fread("A;B\n8;2,34\n", dec=","), data.table(A=8L, B=2.34))
test(1442, fread("A;B\n1;2,34\n", sep=".", dec="."), error="sep == dec ('.') is not allowed")
test(1443, fread("A;B\n1;2,34\n", dec=",", sep=","), error="sep == dec (',') is not allowed")

# sep=".", issue #502
input = paste( paste("192.168.4.", 1:10, sep=""), collapse="\n")
test(1444.1, fread(input, sep=".", dec="*"), ans<-data.table(V1=192L,V2=168L,V3=4L,V4=1:10))
test(1444.2, fread(input, sep=".", dec=","), ans)
test(1444.2, fread(input, sep=".", dec=","), ans<-data.table(V1=192L,V2=168L,V3=4L,V4=1:10))
test(1444.3, fread(paste(paste("192. 168. 4. ", 1:10, sep = ""), collapse="\n"), sep=".", dec=","), ans)
test(1444.4, fread(paste(paste("Hz.BB.GHG.", 1:10, sep = ""), collapse="\n"), sep=".", dec=","),
data.table(V1="Hz",V2="BB",V3="GHG",V4=1:10))
Expand Down Expand Up @@ -16846,3 +16845,74 @@ A = data.table(A=c(complex(real = 1:3, imaginary=c(0, -1, 1)), NaN))
test(2138.3, rbind(A,B), data.table(A=c(as.character(A$A), B$A)))
A = data.table(A=as.complex(rep(NA, 5)))
test(2138.4, rbind(A,B), data.table(A=c(as.character(A$A), B$A)))

# tests caught by introducing newlines in #4301
test(2139.01, getDTthreads(8L), error="'verbose' must be TRUE or FALSE")
test(2139.02, setDTthreads(1:2), error='threads= must be either NULL.*length 2')
test(2139.03, setDTthreads(1+0i), error='threads= must be either NULL.*type integer/numeric')
DT = data.table(1L)
invisible(alloc.col(DT, 10010L))
test(2139.04, alloc.col(DT), DT, warning='greater than 10,000 items over-allocated')
test(2139.05, alloc.col(DT, verbose = 1L), error="verbose must be TRUE or FALSE")
test(2139.06, set(data.table(NULL), NULL, 1L, 1L), error="Input data.table has no columns")
test(2139.07, set(1L, NULL, 1L, 1L), error="object passed to assign isn't type VECSXP")
names(DT) = NULL
test(2139.08, set(DT, NULL, 1L, 2L), error="data.table passed to assign has no names")
test(2139.09, alloc.col(NULL), error="object passed to alloccol is NULL")
test(2139.10, alloc.col(1L), error="object passed to alloccol isn't type VECSXP")
test(2139.11, set(NULL, NULL, 1L, 1L), error="object passed to assign is NULL")
setDF(DT)
names(DT) = 'V1'
test(2139.12, set(DT, NULL, 'V2', 2L), error="set() on a data.frame is for changing existing columns")
setDT(DT)
invisible(alloc.col(DT, 10010L))
test(2139.13, set(DT, NULL, 'V2', 2L), DT, warning="greater than 10,000 items over-allocated")

txt = 'a,b\n1,2'
test(2139.14, fread(txt, sep=',', quote=','), error="sep == quote (',') is not allowed")
test(2139.15, fread(txt, dec='&'), error="dec='&' not allowed")
test(2139.16, fread(txt, quote='.', dec='.'), error="quote == dec ('.') is not allowed")
test(2139.17, fread(txt, integer64=letters), error="'integer64' must be a single character string")
test(2139.18, fread(txt, colClasses = list()), error="colClasses is type list but has no names")

test(2139.19, setNumericRounding(1:2), error="Rounding level must be a length-1 integer or numeric vector")
test(2139.20, setNumericRounding(-1), error="Rounding level must be 2, 1 or 0")

DT = data.table(1L)
names(DT) = NULL
test(2139.21, setcolorder(DT, 1L), error="data.table passed to setcolorder has no names")

# uniqueNlogical
test(2139.22, uniqueN(NA, na.rm=1), error="na.rm must be TRUE or FALSE")
test(2139.23, rleid(1, 1:2), error="All elements of input list must be of same length")
test(2139.24, uniqlengths(1L, 1:3), error="Input argument 'n' to 'uniqlengths' must be an integer vector of length 1")

old = options(datatable.optimize = 2L)
DT = data.table(a = 1:2, b = 1, f = factor(1), l = list(1))
test(2139.25, DT[ , sum(b, na.rm=1), by=a], error="na.rm must be TRUE or FALSE")
test(2139.26, DT[ , sum(f), by=a], error="sum is not meaningful for factors")
test(2139.27, DT[ , mean(b, na.rm=1), by=a], error="na.rm must be TRUE or FALSE")
test(2139.28, DT[ , mean(l), by=a], error="GForce mean can only be applied to columns, not .SD or similar")
test(2139.29, DT[ , mean(f), by=a], error="mean is not meaningful for factors")
test(2139.30, DT[ , min(b, na.rm=1), by=a], error="na.rm must be TRUE or FALSE")
test(2139.31, DT[ , min(l), by=a], error="GForce min can only be applied to columns, not .SD or similar")
test(2139.32, DT[ , min(f), by=a], error="min is not meaningful for factors")
test(2139.33, DT[ , max(b, na.rm=1), by=a], error="na.rm must be TRUE or FALSE")
test(2139.34, DT[ , max(l), by=a], error="GForce max can only be applied to columns, not .SD or similar")
test(2139.35, DT[ , max(f), by=a], error="max is not meaningful for factors")
test(2139.36, DT[ , median(b, na.rm=1), by=a], error="na.rm must be TRUE or FALSE")
test(2139.37, DT[ , median(l), by=a], error="GForce median can only be applied to columns, not .SD or similar")
test(2139.38, DT[ , median(f), by=a], error="median is not meaningful for factors")
test(2139.39, DT[ , var(b, na.rm=1), by=a], error="na.rm must be TRUE or FALSE")
test(2139.40, DT[ , var(l), by=a], error="GForce var/sd can only be applied to columns, not .SD or similar")
test(2139.41, DT[ , var(f), by=a], error="var/sd is not meaningful for factors")
test(2139.42, DT[ , prod(b, na.rm=1), by=a], error="na.rm must be TRUE or FALSE")
test(2139.43, DT[ , prod(l), by=a], error="GForce prod can only be applied to columns, not .SD or similar")
test(2139.44, DT[ , prod(f), by=a], error="prod is not meaningful for factors")
options(old)

test(2139.45, vecseq(NA, NA, NA), error="x must be an integer vector")
test(2139.46, vecseq(1L, NA, NA), error="len must be an integer vector")
test(2139.47, vecseq(1L, 1:2, NA), error="x and len must be the same length")
test(2139.48, vecseq(1L, 1L, 1L), error="clamp must be a double vector length 1")
test(2139.49, vecseq(1L, 1L, -1), error="clamp must be positive")
Loading