Skip to content

Commit 8ac2ae0

Browse files
Totally drop isReallyReal, just use isRealReallyInt with flavors for 32/64
1 parent 0d8ae09 commit 8ac2ae0

File tree

11 files changed

+56
-57
lines changed

11 files changed

+56
-57
lines changed

R/IDateTime.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ round.IDate = function(x, digits=c("weeks", "months", "quarters", "years"), ...)
9999
# TODO: investigate Ops.IDate method a la Ops.difftime
100100
if (inherits(e1, "difftime") || inherits(e2, "difftime"))
101101
internal_error("difftime objects may not be added to IDate, but Ops dispatch should have intervened to prevent this") # nocov
102-
if (isReallyReal(e1) || isReallyReal(e2)) {
102+
if (isRealReallyInt32(e1) || isRealReallyInt32(e2)) {
103103
return(`+.Date`(e1, e2))
104104
# IDate doesn't support fractional days; revert to base Date
105105
}
@@ -120,7 +120,7 @@ round.IDate = function(x, digits=c("weeks", "months", "quarters", "years"), ...)
120120
if (inherits(e2, "difftime"))
121121
internal_error("difftime objects may not be subtracted from IDate, but Ops dispatch should have intervened to prevent this") # nocov
122122

123-
if ( isReallyReal(e2) ) {
123+
if ( isRealReallyInt32(e2) ) {
124124
# IDate deliberately doesn't support fractional days so revert to base Date
125125
return(base::`-.Date`(as.Date(e1), e2))
126126
# can't call base::.Date directly (last line of base::`-.Date`) as tried in PR#3168 because

R/bmerge.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
9292
if (xclass=="integer64" || iclass=="integer64") {
9393
nm = c(iname, xname)
9494
if (xclass=="integer64") { w=i; wc=ic; wclass=iclass; } else { w=x; wc=xc; wclass=xclass; nm=rev(nm) } # w is which to coerce
95-
if (wclass=="integer" || (wclass=="double" && !isReallyReal(w[[wc]], vs='i64'))) {
95+
if (wclass=="integer" || (wclass=="double" && !isRealReallyInt64(w[[wc]]))) {
9696
if (verbose) catf("Coercing %s column %s%s to type integer64 to match type of %s.\n", wclass, nm[1L], if (wclass=="double") " (which has integer64 representation, e.g. no fractions)" else "", nm[2L])
9797
set(w, j=wc, value=bit64::as.integer64(w[[wc]]))
9898
} else stopf("Incompatible join types: %s is type integer64 but %s is type double and cannot be coerced to integer64 (e.g. has fractions)", nm[2L], nm[1L])
9999
} else {
100100
# just integer and double left
101101
if (iclass=="double") {
102-
if (!isReallyReal(i[[ic]])) {
102+
if (!isRealReallyInt32(i[[ic]])) {
103103
# common case of ad hoc user-typed integers missing L postfix joining to correct integer keys
104104
# we've always coerced to int and returned int, for convenience.
105105
if (verbose) catf("Coercing double column %s (which contains no fractions) to type integer to match type of %s.\n", iname, xname)

R/data.table.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,9 +3240,9 @@ is_constantish = function(q, check_singleton=FALSE) {
32403240
if (length(RHS) != nrow(x)) stopf("RHS of %s is length %d which is not 1 or nrow (%d). For robustness, no recycling is allowed (other than of length 1 RHS). Consider %%in%% instead.", operator, length(RHS), nrow(x))
32413241
return(NULL) # DT[colA == colB] regular element-wise vector scan
32423242
}
3243-
if ( mode(x[[col]]) != mode(RHS) || # mode() so that doubleLHS/integerRHS and integerLHS/doubleRHS!isReallyReal are optimized (both sides mode 'numeric')
3243+
if ( mode(x[[col]]) != mode(RHS) || # mode() so that doubleLHS/integerRHS and integerLHS/doubleRHS!isRealReallyInt32 are optimized (both sides mode 'numeric')
32443244
is.factor(x[[col]])+is.factor(RHS) == 1L || # but factor is also mode 'numeric' so treat that separately
3245-
is.integer(x[[col]]) && isReallyReal(RHS) ) { # and if RHS contains fractions then don't optimize that as bmerge truncates the fractions to match to the target integer type
3245+
is.integer(x[[col]]) && isRealReallyInt32(RHS) ) { # and if RHS contains fractions then don't optimize that as bmerge truncates the fractions to match to the target integer type
32463246
# re-direct non-matching type cases to base R, as data.table's binary
32473247
# search based join is strict in types. #957, #961 and #1361
32483248
# the mode() checks also deals with NULL since mode(NULL)=="NULL" and causes this return, as one CRAN package (eplusr 0.9.1) relies on

R/wrappers.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ colnamesInt = function(x, cols, check_dups=FALSE, skip_absent=FALSE) .Call(Ccoln
1717

1818
testMsg = function(status=0L, nx=2L, nk=2L) .Call(CtestMsgR, as.integer(status)[1L], as.integer(nx)[1L], as.integer(nk)[1L])
1919

20-
isRealReallyInt = function(x) .Call(CisRealReallyIntR, x)
21-
isReallyReal = function(x, vs='i32') .Call(CisReallyReal, x, identical(vs, 'i64'))
20+
isRealReallyInt32 = function(x) .Call(CisRealReallyInt32R, x)
21+
isRealReallyInt64 = function(x) .Call(CisRealReallyInt64R, x)
2222

2323
coerceAs = function(x, as, copy=TRUE) .Call(CcoerceAs, x, as, copy)

inst/tests/tests.Rraw

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
5656
internal_error = data.table:::internal_error
5757
is_na = data.table:::is_na
5858
is.sorted = data.table:::is.sorted
59-
isReallyReal = data.table:::isReallyReal
60-
isRealReallyInt = data.table:::isRealReallyInt
59+
isRealReallyInt32 = data.table:::isRealReallyInt32
6160
is_utc = data.table:::is_utc
6261
melt.data.table = data.table:::melt.data.table # for test 1953.4
6362
messagef = data.table:::messagef
@@ -7344,22 +7343,22 @@ if (test_bit64) {
73447343
X = list(a = 4:1, b=runif(4))
73457344
test(1513, setkey(as.data.table(X), a), setDT(X, key="a"))
73467345

7347-
# Adding tests for `isReallyReal`
7346+
# Adding tests for `isRealReallyInt32`
73487347
x = as.numeric(sample(10))
7349-
test(1514.1, isReallyReal(x), 0L)
7348+
test(1514.1, isRealReallyInt32(x), TRUE)
73507349
x = as.numeric(sample(c(1:5, NA)))
7351-
test(1514.2, isReallyReal(x), 0L) # NAs in numeric can be coerced to integer NA without loss
7350+
test(1514.2, isRealReallyInt32(x), TRUE) # NAs in numeric can be coerced to integer NA without loss
73527351
x = c(1:2, NaN, NA)
7353-
test(1514.3, isReallyReal(x), 3L)
7352+
test(1514.3, isRealReallyInt32(x), FALSE)
73547353
x = c(1:2, Inf, NA)
7355-
test(1514.4, isReallyReal(x), 3L)
7354+
test(1514.4, isRealReallyInt32(x), FALSE)
73567355
x = c(1:2, -Inf, NA)
7357-
test(1514.5, isReallyReal(x), 3L)
7356+
test(1514.5, isRealReallyInt32(x), FALSE)
73587357
x = runif(2)
7359-
test(1514.6, isReallyReal(x), 1L)
7358+
test(1514.6, isRealReallyInt32(x), FALSE)
73607359
x = numeric()
7361-
test(1514.7, isReallyReal(x), 0L)
7362-
test(1514.8, isReallyReal(9L), 0L)
7360+
test(1514.7, isRealReallyInt32(x), TRUE)
7361+
test(1514.8, isRealReallyInt32(9L), TRUE)
73637362

73647363
# #1091
73657364
options(datatable.prettyprint.char = 5L)
@@ -17590,18 +17589,18 @@ test(2204, as.data.table(mtcars, keep.rownames='model', key='model'),
1759017589

1759117590
# 2205 tested nanotime moved to other.Rraw 27, #5516
1759217591

17593-
# isRealReallyInt, #3966
17594-
test(2206.01, isRealReallyInt(c(-2147483647.0, NA, 0.0, 2147483647.0)), TRUE)
17595-
test(2206.02, isRealReallyInt(2147483648.0), FALSE) # >INT_MAX
17596-
test(2206.03, isRealReallyInt(-2147483648.0), FALSE) # <=INT_MIN since INT_MIN==NA_integer_
17597-
test(2206.04, isRealReallyInt(c(5,-5,2147483648)), FALSE) # test real last position
17598-
test(2206.05, isRealReallyInt(NaN), FALSE)
17599-
test(2206.06, isRealReallyInt(+Inf), FALSE)
17600-
test(2206.07, isRealReallyInt(-Inf), FALSE)
17601-
test(2206.08, isRealReallyInt(0.1), FALSE)
17602-
test(2206.09, isRealReallyInt(numeric()), TRUE)
17603-
test(2206.10, isRealReallyInt(9L), FALSE) # must be type double
17604-
test(2206.11, isRealReallyInt(integer()), FALSE)
17592+
# isRealReallyInt32, #3966
17593+
test(2206.01, isRealReallyInt32(c(-2147483647.0, NA, 0.0, 2147483647.0)), TRUE)
17594+
test(2206.02, isRealReallyInt32(2147483648.0), FALSE) # >INT_MAX
17595+
test(2206.03, isRealReallyInt32(-2147483648.0), FALSE) # <=INT_MIN since INT_MIN==NA_integer_
17596+
test(2206.04, isRealReallyInt32(c(5,-5,2147483648)), FALSE) # test real last position
17597+
test(2206.05, isRealReallyInt32(NaN), FALSE)
17598+
test(2206.06, isRealReallyInt32(+Inf), FALSE)
17599+
test(2206.07, isRealReallyInt32(-Inf), FALSE)
17600+
test(2206.08, isRealReallyInt32(0.1), FALSE)
17601+
test(2206.09, isRealReallyInt32(numeric()), TRUE)
17602+
test(2206.10, isRealReallyInt32(9L), FALSE) # must be type double
17603+
test(2206.11, isRealReallyInt32(integer()), FALSE)
1760517604

1760617605
# dcast supports complex value to cast, #4855
1760717606
DT = CJ(x=1:3, y=letters[1:2])

src/between.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
3030
const bool verbose = GetVerbose();
3131

3232
if (isInteger(x)) {
33-
if ((isInteger(lower) || isRealReallyInt(lower)) &&
34-
(isInteger(upper) || isRealReallyInt(upper))) { // #3517 coerce to num to int when possible
33+
if ((isInteger(lower) || isRealReallyInt32(lower)) &&
34+
(isInteger(upper) || isRealReallyInt32(upper))) { // #3517 coerce to num to int when possible
3535
if (!isInteger(lower)) {
3636
lower = PROTECT(coerceVector(lower, INTSXP)); nprotect++;
3737
}

src/data.table.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,10 @@ SEXP coalesce(SEXP x, SEXP inplace);
243243
// utils.c
244244
bool within_int32_repres(double x);
245245
bool within_int64_repres(double x);
246-
bool isRealReallyInt(SEXP x);
247-
SEXP isRealReallyIntR(SEXP x);
248-
SEXP isReallyReal(SEXP x, SEXP i64);
246+
bool isRealReallyInt32(SEXP x);
247+
SEXP isRealReallyInt32R(SEXP x);
248+
bool isRealReallyInt64(SEXP x);
249+
SEXP isRealReallyInt64R(SEXP x);
249250
bool allNA(SEXP x, bool errorForBadType);
250251
SEXP colnamesInt(SEXP x, SEXP cols, SEXP check_dups, SEXP skip_absent);
251252
bool INHERITS(SEXP x, SEXP char_);

src/forder.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,12 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
595595
if (INHERITS(x, char_integer64)) {
596596
range_i64((int64_t *)REAL(x), nrow, &min, &max, &na_count);
597597
} else {
598-
if (verbose && INHERITS(x, char_Date) && INTEGER(isReallyReal(x))[0]==0) {
599-
Rprintf(_("\n*** Column %d passed to forder is a date stored as an 8 byte double but no fractions are present. Please consider a 4 byte integer date such as IDate to save space and time.\n"), col+1);
600-
// Note the (slightly expensive) isReallyReal will only run when verbose is true. Prefix '***' just to make it stand out in verbose output
598+
if (verbose && INHERITS(x, char_Date) && isRealReallyInt32(x)) {
599+
// Note the (slightly expensive) isRealReallyInt32 will only run when verbose is true. Prefix '***' just to make it stand out in verbose output
601600
// In future this could be upgraded to option warning. But I figured that's what we use verbose to do (to trace problems and look for efficiencies).
602601
// If an automatic coerce is desired (see discussion in #1738) then this is the point to do that in this file. Move the INTSXP case above to be
603602
// next, do the coerce of Date to integer now to a tmp, and then let this case fall through to INTSXP in the same way as CPLXSXP falls through to REALSXP.
603+
Rprintf(_("\n*** Column %d passed to forder is a date stored as an 8 byte double but no fractions are present. Please consider a 4 byte integer date such as IDate to save space and time.\n"), col+1);
604604
}
605605
range_d(REAL(x), nrow, &min, &max, &na_count, &infnan_count);
606606
if (min==0 && na_count<nrow) { min=3; max=4; } // column contains no finite numbers and is not-all NA; create dummies to yield positive min-2 later

src/frollR.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ SEXP frollapplyR(SEXP fun, SEXP obj, SEXP k, SEXP fill, SEXP align, SEXP rho) {
229229

230230
if (!isInteger(k)) {
231231
if (isReal(k)) {
232-
if (isRealReallyInt(k)) {
232+
if (isRealReallyInt32(k)) {
233233
SEXP ik = PROTECT(coerceVector(k, INTSXP)); protecti++;
234234
k = ik;
235235
} else {

src/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ R_CallMethodDef callMethods[] = {
101101
{"Cshift", (DL_FUNC) &shift, -1},
102102
{"Ctranspose", (DL_FUNC) &transpose, -1},
103103
{"CanyNA", (DL_FUNC) &anyNA, -1},
104-
{"CisReallyReal", (DL_FUNC) &isReallyReal, -1},
105-
{"CisRealReallyIntR", (DL_FUNC) &isRealReallyIntR, -1},
104+
{"CisRealReallyInt32R", (DL_FUNC) &isRealReallyInt32R, -1},
105+
{"CisRealReallyInt64R", (DL_FUNC) &isRealReallyInt64R, -1},
106106
{"Csetlevels", (DL_FUNC) &setlevels, -1},
107107
{"Crleid", (DL_FUNC) &rleid, -1},
108108
{"Cgmedian", (DL_FUNC) &gmedian, -1},

0 commit comments

Comments
 (0)