Skip to content

Commit

Permalink
Adjusted #1010 fix to account for roll="nearest". Added test.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Jan 27, 2015
1 parent bc6c45b commit b3ecb31
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
keylen = which.first(!key(x) %chin% ansvars)-1L
if (is.na(keylen)) keylen = length(key(x))
if (keylen > length(rightcols) && !.Call(CisOrderedSubset, irows, nrow(x))) keylen = length(rightcols)
if (keylen && ((is.data.table(i) && haskey(i)) || is.logical(i) || (.Call(CisOrderedSubset, irows, nrow(x)) && (!roll || length(irows) == 1L)))) # see #1010. don't set key when i has no key, but irows is ordered and roll != FALSE
if (keylen && ((is.data.table(i) && haskey(i)) || is.logical(i) || (.Call(CisOrderedSubset, irows, nrow(x)) && ((roll == FALSE) || length(irows) == 1L)))) # see #1010. don't set key when i has no key, but irows is ordered and roll != FALSE
setattr(ans,"sorted",head(key(x),keylen))
}
setattr(ans, "class", class(x)) # fix for #5296
Expand Down Expand Up @@ -1177,7 +1177,7 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
byval = i
bynames = head(key(x),length(leftcols))
allbyvars = NULL
bysameorder = haskey(i) || (is.sorted(f__) && (!roll || length(f__) == 1L)) # Fix for #1010
bysameorder = haskey(i) || (is.sorted(f__) && ((roll == FALSE) || length(f__) == 1L)) # Fix for #1010
## 'av' correct here ?? *** TO DO ***
xjisvars = intersect(av, names(x)[rightcols]) # no "x." for xvars.
# if 'get' is in 'av' use all cols in 'i', fix for bug #5443
Expand Down
1 change: 1 addition & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -5832,6 +5832,7 @@ test(1469.2, key(DT[J(c(2,0)), .(x,y), roll=TRUE]), NULL)
test(1469.3, key(DT[J(c(2,0)), y, roll=TRUE, by=.EACHI]), NULL)
test(1469.4, key(DT[J(c(2,0))]), NULL)
test(1469.5, key(DT[SJ(c(2,0)), roll=TRUE]), "x")
test(1469.6, key(DT[J(c(2,0)), roll="nearest"]), NULL)

# 1007 fix, dealing with Inf and -Inf correctly in rolling joins.
DT = data.table(x=c(-Inf, 3, Inf), y=1:3, key="x")
Expand Down

0 comments on commit b3ecb31

Please sign in to comment.