Skip to content

Commit 33d7009

Browse files
committed
ensure same types for test
1 parent d41bbf2 commit 33d7009

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

R/bmerge.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
113113
# we've always coerced to int and returned int, for convenience.
114114
if (length(ic_idx)>1L) {
115115
xc_idx = xcols[ic_idx]
116-
for (b in which(vapply_1c(x[0L, ..xc_idx], getClass) == "double")) {
116+
for (b in which(vapply_1c(x[0L, xc_idx, with=FALSE], getClass) == "double")) {
117117
xb = xcols[b]
118118
if (isReallyReal(x[[xb]])) {
119119
coerce_x = FALSE
@@ -128,7 +128,7 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
128128
set(callersi, j=ic, value=val) # change the shallow copy of i up in [.data.table to reflect in the result, too.
129129
if (length(ic_idx)>1L) {
130130
xc_idx = xcols[ic_idx]
131-
for (b in which(vapply_1c(x[0L, ..xc_idx], getClass) == "double")) {
131+
for (b in which(vapply_1c(x[0L, xc_idx, with=FALSE], getClass) == "double")) {
132132
xb = xcols[b]
133133
if (verbose) catf("Coercing double column %s (which contains no fractions) to type integer to match type of %s.\n", paste0("x.", names(x)[xb]), xname)
134134
set(x, j=xb, value=cast_with_atts(x[[xb]], as.integer))
@@ -146,7 +146,7 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
146146
set(i, j=ic, value=val)
147147
if (length(ic_idx)>1L) {
148148
xc_idx = xcols[ic_idx]
149-
for (b in which(vapply_1c(x[0L, ..xc_idx], getClass) == "integer")) {
149+
for (b in which(vapply_1c(x[0L, xc_idx, with=FALSE], getClass) == "integer")) {
150150
xb = xcols[b]
151151
if (verbose) catf("Coercing integer column %s to type double for join to match type of %s.\n", paste0("x.", names(x)[xb]), xname)
152152
set(x, j=xb, value=cast_with_atts(x[[xb]], as.double))

inst/tests/tests.Rraw

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12226,10 +12226,11 @@ DT1 = data.table(RANDOM_STRING = rand_strings(n),
1222612226
DATE = sample(seq(as.Date('2016-01-01'), as.Date('2016-12-31'), by="day"), n, replace=TRUE))
1222712227
DT2 = data.table(RANDOM_STRING = rand_strings(n),
1222812228
START_DATE = sample(seq(as.Date('2015-01-01'), as.Date('2017-12-31'), by="day"), n, replace=TRUE))
12229+
as.intDate = function(x) .Date(as.integer(as.Date(x)))
1222912230
DT2[, EXPIRY_DATE := START_DATE + floor(runif(1000, 200,300))]
12230-
DT1[, DT1_ID := .I][, DATE := as.Date(DATE)]
12231+
DT1[, DT1_ID := .I][, DATE := as.intDate(DATE)]
1223112232
cols = c("START_DATE", "EXPIRY_DATE")
12232-
DT2[, DT2_ID := .I][, (cols) := lapply(.SD, as.Date), .SDcols=cols]
12233+
DT2[, DT2_ID := .I][, (cols) := lapply(.SD, as.intDate), .SDcols=cols]
1223312234
ans1 = DT2[DT1, on=.(RANDOM_STRING, START_DATE <= DATE, EXPIRY_DATE >= DATE), .N, by=.EACHI ]$N > 0L
1223412235
tmp = DT1[DT2, on=.(RANDOM_STRING, DATE >= START_DATE, DATE <= EXPIRY_DATE), which=TRUE, nomatch=0L]
1223512236
ans2 = DT1[, DT1_ID %in% tmp]

0 commit comments

Comments
 (0)