diff --git a/NEWS.md b/NEWS.md index 68d69b8d1a..99b369b540 100644 --- a/NEWS.md +++ b/NEWS.md @@ -113,6 +113,8 @@ unit = "s") 15. `all.equal(DT1, DT2, ignore.row.order=TRUE)` could return TRUE incorrectly in the presence of NAs, [#4422](https://github.com/Rdatatable/data.table/issues/4422). +16. Non-equi joins now automatically set `allow.cartesian=TRUE`, [4489](https://github.com/Rdatatable/data.table/issues/4489). Thanks to @Henrik-P for reporting. + ## NOTES 0. Retrospective license change permission was sought from and granted by 4 contributors who were missed in [PR#2456](https://github.com/Rdatatable/data.table/pull/2456), [#4140](https://github.com/Rdatatable/data.table/pull/4140). We had used [GitHub's contributor page](https://github.com/Rdatatable/data.table/graphs/contributors) which omits 3 of these due to invalid email addresses, unlike GitLab's contributor page which includes the ids. The 4th omission was a PR to a script which should not have been excluded; a script is code too. We are sorry these contributors were not properly credited before. They have now been added to the contributors list as displayed on CRAN. All the contributors of code to data.table hold its copyright jointly; your contributions belong to you. You contributed to data.table when it had a particular license at that time, and you contributed on that basis. This is why in the last license change, all contributors of code were consulted and each had a veto. diff --git a/R/data.table.R b/R/data.table.R index 08db908db5..20d7cfa396 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -428,6 +428,9 @@ replace_dot_alias = function(e) { on_ops = .parse_on(substitute(on), isnull_inames) on = on_ops[[1L]] ops = on_ops[[2L]] + if (any(ops > 1L)) { ## fix for #4489; ops = c("==", "<=", "<", ">=", ">", "!=") + allow.cartesian = TRUE + } # TODO: collect all '==' ops first to speeden up Cnestedid rightcols = colnamesInt(x, names(on), check_dups=FALSE) leftcols = colnamesInt(i, unname(on), check_dups=FALSE) diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 6ce67d4dbb..85a9dbe771 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -16882,7 +16882,13 @@ test(2138.3, rbind(A,B), data.table(A=c(as.character(A$A), B$A))) A = data.table(A=as.complex(rep(NA, 5))) test(2138.4, rbind(A,B), data.table(A=c(as.character(A$A), B$A))) -# all.equal ignore row order improperly handle NAs #4422 +# all.equal ignore row order improperly handle NAs, #4422 d1 = data.table(a=1:2, b=c(1L,NA)) d2 = data.table(a=1:2, b=1:2) -test(2139.1, all.equal(d1, d2, ignore.row.order=TRUE), "Dataset 'current' has rows not present in 'target'") +test(2139, all.equal(d1, d2, ignore.row.order=TRUE), "Dataset 'current' has rows not present in 'target'") + +# Set allow.cartesian = TRUE when non-equi, #4489 +dt = data.table(time = 1:8, v = INT(5,7,6,1,8,4,2,3)) +dt[time == 2L, v := 2L] +dt[time == 7L, v := 7L] +test(2140, dt[dt, on=.(time>time, v>v), .N, by=.EACHI], data.table(time=1:8, v=INT(5,2,6,1,8,4,7,3), N=INT(3,5,2,4,0,1,0,0)))