Skip to content

Commit

Permalink
Closes #1361. Auto indexing handles logical subsets on factor cols pr…
Browse files Browse the repository at this point in the history
…operly.
  • Loading branch information
arunsrinivasan committed Dec 25, 2015
1 parent 871687c commit 405f115
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
if (length(RHS)!=nrow(x)) stop("RHS of == is length ",length(RHS)," which is not 1 or nrow (",nrow(x),"). For robustness, no recycling is allowed (other than of length 1 RHS). Consider %in% instead.")
i = x[[isub2]] == RHS # DT[colA == colB] regular element-wise vector scan
} else if ( (is.integer(x[[isub2]]) && is.double(RHS) && isReallyReal(RHS)) || (mode(x[[isub2]]) != mode(RHS) && !(class(x[[isub2]]) %in% c("character", "factor") &&
class(RHS) %in% c("character", "factor"))) ) {
class(RHS) %in% c("character", "factor"))) ||
(is.factor(x[[isub2]]) && !is.factor(RHS) && mode(RHS)=="numeric") ) { # fringe case, #1361. TODO: cleaner way of doing these checks.
# re-direct all non-matching mode cases to base R, as data.table's binary
# search based join is strict in types. #957 and #961.
i = if (isub[[1L]] == "==") x[[isub2]] == RHS else x[[isub2]] %in% RHS
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@

20. `fread` converts columns to `factor` type when used along with `colClasses` argument, [#721](https://github.com/Rdatatable/data.table/issues/721). Thanks @AmyMikhail.

21. Auto indexing handles logical subset of factor column using numeric value properly, [#1361](https://github.com/Rdatatable/data.table/issues/1361). Thanks @mplatzer.

#### NOTES

1. Updated error message on invalid joins to reflect the new `on=` syntax, [#1368](https://github.com/Rdatatable/data.table/issues/1368). Thanks @MichaelChirico.
Expand Down
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -7272,6 +7272,11 @@ test(1586.2, fread(text, colClasses=c(x="factor")), data.table(x=factor(1:2), y=
text="x,y\n2,a\n1,q\n3,c\n"
test(1587, fread(text, key="y"), setDT(fread(text), key="y"))

# fix for #1361
dt = data.table(i=1:10, f=as.factor(1:10))
test(1588.1, dt[f %in% 3:4], dt[3:4])
test(1588.2, dt[f == 3], dt[3])

##########################

# TODO: Tests involving GForce functions needs to be run with optimisation level 1 and 2, so that both functions are tested all the time.
Expand Down

0 comments on commit 405f115

Please sign in to comment.