Skip to content

Commit

Permalink
Closes #488 (again). More fixes for integer64 NA handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Mar 17, 2015
1 parent 8c46f46 commit 4db0c43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 17 additions & 1 deletion inst/tests/tests.Rraw
Expand Up @@ -6128,8 +6128,24 @@ test(1499, ans1, ans2)

# Fix for #488
if ("package:bit64" %in% search()) {
test(1500, fread("x,y\n0,\n", colClasses = list(integer64 = "y")),
test(1500.1, fread("x,y\n0,\n", colClasses = list(integer64 = "y")),
data.table(x=0L, y=as.integer64(NA)))
# more tests after new fix
test(1500.2, fread("x,y\n0,12345678901234\n0,\n0,\n0,\n0,\n,\n,\n,\n,\n,\n,\n,\n,\n,\n,\n,\n12345678901234,\n0,\n0,\n0,\n0,\n0,\n"),
data.table(x=as.integer64(c(rep(0L, 5L), rep(NA, 11), 12345678901234, rep(0L,5L))),
y=as.integer64(c(12345678901234, rep(NA,21)))))

x = c("12345678901234", rep("NA", 178), "a")
y = sample(letters, length(x), TRUE)
ll = paste(x,y, sep=",", collapse="\n")
test(1500.3, fread(ll),
data.table(V1=c("12345678901234", rep("", 178), "a"), V2=y), warning="Bumped column 1 to type character on data")

x = c("12345678901234", rep("NA", 178), "0.5")
y = sample(letters, length(x), TRUE)
ll = paste(x,y, sep=",", collapse="\n")
test(1500.4, fread(ll), data.table(V1=suppressWarnings(as.numeric(x)), V2=y))

}

# dcast.data.table new tests
Expand Down
6 changes: 4 additions & 2 deletions src/fread.c
Expand Up @@ -341,7 +341,9 @@ static SEXP coerceVectorSoFar(SEXP v, int oldtype, int newtype, R_len_t sofar, R
case SXP_INT64:
switch(oldtype) {
case SXP_LGL : case SXP_INT :
for (i=0; i<sofar; i++) REAL(newv)[i] = (INTEGER(v)[i]==NA_INTEGER ? NA_REAL : (u.l=(long long)INTEGER(v)[i],u.d));
for (i=0; i<sofar; i++) {
REAL(newv)[i] = (INTEGER(v)[i]==NA_INTEGER ? (u.l=NAINT64,u.d) : (u.l=(long long)INTEGER(v)[i],u.d));
}
break;
default :
STOP("Internal error: attempt to bump from type %d to type %d. Please report to datatable-help.", oldtype, newtype);
Expand All @@ -353,7 +355,7 @@ static SEXP coerceVectorSoFar(SEXP v, int oldtype, int newtype, R_len_t sofar, R
for (i=0; i<sofar; i++) REAL(newv)[i] = (INTEGER(v)[i]==NA_INTEGER ? NA_REAL : (double)INTEGER(v)[i]);
break;
case SXP_INT64 :
for (i=0; i<sofar; i++) REAL(newv)[i] = (ISNA(REAL(v)[i]) ? NA_REAL : (double)(*(long long *)&REAL(v)[i]));
for (i=0; i<sofar; i++) REAL(newv)[i] = ((*(long long *)&REAL(v)[i] == NAINT64) ? NA_REAL : (double)(*(long long *)&REAL(v)[i]));
break;
default :
STOP("Internal error: attempt to bump from type %d to type %d. Please report to datatable-help.", oldtype, newtype);
Expand Down

0 comments on commit 4db0c43

Please sign in to comment.