Skip to content

Commit

Permalink
fread drop when NULL in colClasses (#3277)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle authored Jan 12, 2019
1 parent ca34dd3 commit 7d2acb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -11143,6 +11143,11 @@ test(1825.15, fread(str, colClasses=list(numeric=2, NULL=3:5), drop=1),
data.table(x2=c(2,4), x3=c(1.5,2.5), x4=c("T","F"), x5=c("cc","ff")),
warning="Ignoring the NULL item in colClasses= because select= or drop= has been used") # warning because drop != colClasses$`NULL`
test(1825.16, fread(str, colClasses=(cl<-list(numeric=2, NULL=3:5)), drop=cl$`NULL`), data.table(x1=INT(1,3), x2=c(2,4))) # cover commit f0bd6e3
# NULL didn't work in 1.11.0-1.11.8 so some usage exists where drop= is used to respecify the NULLs. The warning could be reintroduced in future.
# https://github.com/Rdatatable/data.table/issues/3233#issuecomment-453674647
test(1825.17, fread(str, colClasses=c("integer","integer","NULL","character","NULL"), drop=3), data.table(x1=INT(1,3), x2=INT(2,4), x4=c("T","F")))
test(1825.18, fread(str, colClasses=c("integer","numeric","NULL","character","NULL"), drop=3:4), data.table(x1=INT(1,3), x2=c(2,4)))
test(1825.19, fread(str, drop=6), data.table(x1=INT(1,3), x2=INT(2,4), x3=c(1.5,2.5), x4=c("T","F"), x5=c("cc","ff")), warning="Column number 6 (drop[1]) is out of range [1,ncol=5]")

# issue 2351
set.seed(1)
Expand Down
5 changes: 4 additions & 1 deletion src/freadR.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ _Bool userOverride(int8_t *type, lenOff *colNames, const char *anchor, int ncol)
if (k<1 || k>ncol) {
DTWARN("Column number %d (drop[%d]) is out of range [1,ncol=%d]",k,j+1,ncol);
} else {
if (type[k-1] == CT_DROP) STOP("Duplicates detected in drop");
// if (type[k-1] == CT_DROP) DTWARN("drop= contains duplicates");
// NULL in colClasses didn't work between 1.11.0 and 1.11.8 so people have been using drop= to re-specify the NULL columns in colClasses. Now that NULL in colClasses works
// from v1.12.0 there is no easy way to distinguish dups in drop= from drop overlapping with NULLs in colClasses. But it's unambiguous that it was intended to remove these
// columns, so no need for warning.
type[k-1] = CT_DROP;
}
}
Expand Down

0 comments on commit 7d2acb5

Please sign in to comment.