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

setDF deletes the index attribute #4893

Merged
merged 14 commits into from
Jul 27, 2021
Prev Previous commit
Next Next commit
Merge branch 'master' into 4889
  • Loading branch information
mattdowle authored Jul 27, 2021
commit 088ac4e4d22a15855723ac926189f57697bcf9d0
67 changes: 64 additions & 3 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -17742,10 +17742,71 @@ test(2191, DT[1:5, sum(v), by=.(i5 = 1:5 %% 2L), verbose=TRUE], data.table(i5=1:
test(2192.1, as.IDate(c('', '2020-01-01')), structure(c(NA_integer_, 18262L), class=c("IDate","Date")))
test(2192.2, as.IDate(c('2020-01-01', '')), structure(c(18262L, NA_integer_), class=c("IDate","Date")))

if (test_bit64) {
# subassign coerce to integer64 was fixed in 1.12.4, #2530
DT = data.table(a = as.integer64(1:10))
DT[a==1, a:=12]
DT[a==2, a:=as.integer64(13)]
test(2193.1, DT, data.table(a = as.integer64(c(12,13,3:10))))

# X[Y,,by=.EACHI] when Y contains integer64 also fixed in 1.12.4, #3779
X = data.table(x=1:3)
Y = data.table(x=1:2, y=as.integer64(c(10,20)))
test(2193.2, X[Y, `:=`(y=i.y), on="x", by=.EACHI], data.table(x=1:3, y=as.integer64(10L,20L,NA)))
}

# compatibility of endsWith backport with base::endsWith
if (exists('endsWith', 'package:base', inherits=FALSE)) {
DTendsWith = function(x, stub) {n=nchar(x); substr(x, n-nchar(stub)+1L, n)==stub}
BSendsWith = base::endsWith
test(2194.1, DTendsWith('abcd', 'd'), BSendsWith('abcd', 'd'))
test(2194.2, DTendsWith(letters, 'e'), BSendsWith(letters, 'e'))
test(2194.3, DTendsWith(NA_character_, 'a'), BSendsWith(NA_character_, 'a'))
test(2194.4, DTendsWith(character(), 'a'), BSendsWith(character(), 'a'))
# file used in encoding tests
txt = readLines(testDir("issue_563_fread.txt"))
test(2194.5, DTendsWith(txt, 'B'), BSendsWith(txt, 'B'))
}

# uniqueN(x, by=character()) was internal error, #4594
DT = data.table(idx=c(1L,2L,1L,3L), value="val")
test(2195.1, uniqueN(DT, by=character(0L)), 3L)
test(2195.2, uniqueN(DT, by=NULL), 3L)
test(2195.3, unique(DT, by=character(0L)), ans<-data.table(idx=1:3, value="val"))
test(2195.4, unique(DT, by=NULL), ans)
test(2195.5, duplicated(DT, by=character(0L)), ans<-c(FALSE, FALSE, TRUE, FALSE))
test(2195.6, duplicated(DT, by=NULL), ans)
test(2195.7, anyDuplicated(DT, by=character(0L)), 3L)
test(2195.8, anyDuplicated(DT, by=NULL), 3L)

# Improperly quoted character field with fill=TRUE would segfault, #4774 and #5041
test(2196,
fread(paste0(paste(rep(c('a; b'), 100), collapse='\n'), c('\n"a" 2;b')), fill=TRUE, quote='\"'),
data.table(a=c(rep('a', 99), '"a" 2'), b=rep('b', 100)), warning='Found and resolved improper quoting')

# Verbose output would segfault when no header present, out-of-sample type error and fill=TRUE, similar to #4644
# Test vaildity may depend on sampling behaviour of fread since the type bump needs to occur out of sample to trigger the segfault
sampleText = paste0(paste(rep(c('1; 2'), 100), collapse='\n'), c('\n"a";2\n1; 2\n'), paste(rep(c('1; 2'), 100), collapse='\n'))
test(2197, fread(sampleText, fill=TRUE, quote='\"', verbose=TRUE, header=FALSE),
data.table(rep(c("1","a","1"),c(100,1,101)), 2L),
output='Column 1 bumped')

# Need an easier way to in-place merge multiple columns #3184
d1 = data.table(id = 1:5, x1=5:1, x2=5:1/2)
d2 = data.table(id = 2:4, y1=4:2, y2=4:2/2)
test(2198.1, d1[d2, paste0("z", 1:2) := Y, on = "id", env = list(Y = as.list(paste0("i.y", 1:2)))], data.table(id=1:5, x1=5:1, x2=5:1/2, z1=c(NA,4:2,NA), z2=c(NA,4:2/2,NA))) ## using i. prefix
test(2198.2, d1[d2, paste0("z", 1:2) := Y, on = "id", env = list(Y = as.list(paste0("y", 1:2)))], data.table(id=1:5, x1=5:1, x2=5:1/2, z1=c(NA,4:2,NA), z2=c(NA,4:2/2,NA))) ## no i. prefix should still work

# internal error when specifying .SDcols, #4231
test(2199.1, as.data.table(as.list(1:2))[, .SD,.SDcols=(-1L)], data.table(V2=2L))
test(2199.2, as.data.table(as.list(1:2))[, .SD,.SDcols=(-(1L))], data.table(V2=2L))
test(2199.3, as.data.table(as.list(1:3))[, .SD,.SDcols=(-1L)], data.table(V2=2L, V3=3L))
test(2199.4, data.table(V1=-1L, V2=-2L, V3=-3L)[,.SD,.SDcols=-V2:-V1], error="not found")

# setDF now drops index attributes, #4889
d <- data.table(a=1:100, b=1:100)
d = data.table(a=1:100, b=1:100)
setindex(d, a)
setDF(d)
d[1:50, "a"] <- d[51:100, "a"]
d[1:50, "a"] = d[51:100, "a"]
setDT(d)
test(2193, nrow(d[a==99]), as.integer(2))
test(2200, nrow(d[a==99]), 2L)
2 changes: 1 addition & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ SEXP dt_zlib_version() {
#ifndef NOZLIB
snprintf(out, 70, "zlibVersion()==%s ZLIB_VERSION==%s", zlibVersion(), ZLIB_VERSION);
MichaelChirico marked this conversation as resolved.
Show resolved Hide resolved
#else
snprintf(out, 70, "zlib header files were not found when data.table was compiled");
snprintf(out, 70, _("zlib header files were not found when data.table was compiled"));
#endif
return ScalarString(mkChar(out));
}
You are viewing a condensed version of this merge commit. You can view the full changes here.