Skip to content

Commit

Permalink
Closes #1050. Added isReallyReal(), fixed another auto indexing issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Feb 20, 2015
1 parent 3708da2 commit c147bb3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
* While fixing `#932`, issues on subsetting `NA` were also spotted and fixed, for e.g., `DT[x==NA]` or `DT[!x==NA]`.
* Works fine when RHS is of `list` type - quite unusual operation but could happen. Closes [#961](https://github.com/Rdatatable/data.table/issues/961). Thanks to @Gsee for the minimal report.
* Auto indexing errored in some cases when LHS and RHS were not of same type. This is fixed now. Closes [#957](https://github.com/Rdatatable/data.table/issues/957). Thanks to @GSee for the minimal report.
* `DT[x == 2.5]` where `x` is integer type resulted in `val` being coerced to integer (for binary search) and therefore returned incorrect result. This is now identified using the function `isReallyReal()` and if so, auto indexing is turned off. Closes [#1050](https://github.com/Rdatatable/data.table/issues/1050).

7. `as.data.table.list` with list input having 0-length items, e.g. `x = list(a=integer(0), b=3:4)`. `as.data.table(x)` recycles item `a` with `NA`s to fit the length of the longer column `b` (length=2), as before now, but with an additional warning message that the item has been recycled with `NA`. Closes [#847](https://github.com/Rdatatable/data.table/issues/847). Thanks to @tvinodr for the report. This was a regression from 1.9.2.

Expand Down
8 changes: 8 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -6065,6 +6065,14 @@ test(1491.4, replace_dot(ee4), quote(c("a", "b") := list(.SD)))
test(1491.5, replace_dot(ee5), quote(c("a", "b") := list(v1=x^2, v2 = list(.SD[[1L]]))))
test(1491.6, replace_dot(ee6), quote(list(v1=list(.SD), v2=list(lm(. ~ xx)), v3=list(list(x)), v4=list(x^2))))

# Fix for #1050
dt = data.table(x=1:5, y=6:10)
options(datatable.auto.index=FALSE)
ans1 <- dt[x == 2.5]
options(datatable.auto.index=TRUE)
ans2 <- dt[x == 2.5]
test(1492, ans1, ans2)

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


Expand Down
15 changes: 15 additions & 0 deletions src/forder.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,21 @@ SEXP isOrderedSubset(SEXP x, SEXP nrow)
}
*/

SEXP isReallyReal(SEXP x) {
int n, i=0;
SEXP ans;
if (!isReal(x))
error("x must be of type double.");
n = length(x);
ans = PROTECT(allocVector(LGLSXP, 1));
INTEGER(ans)[0] = FALSE;
while (i < n && REAL(x)[i] == abs(REAL(x)[i]))
i++;
if (i != n) LOGICAL(ans)[0] = TRUE;
UNPROTECT(1);
return(ans);
}

void pbin(unsigned long long n)
// trace utility for dev to be used in gdb, since couldn't get stdlib::atoi() to link
{
Expand Down
2 changes: 2 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ SEXP whichwrapper();
SEXP shift();
SEXP transpose();
SEXP anyNA();
SEXP isReallyReal();

// .Externals
SEXP fastmean();
Expand Down Expand Up @@ -116,6 +117,7 @@ R_CallMethodDef callMethods[] = {
{"Cshift", (DL_FUNC) &shift, -1},
{"Ctranspose", (DL_FUNC) &transpose, -1},
{"CanyNA", (DL_FUNC) &anyNA, -1},
{"CisReallyReal", (DL_FUNC) &isReallyReal, -1},
{NULL, NULL, 0}
};

Expand Down

0 comments on commit c147bb3

Please sign in to comment.