diff --git a/NEWS.md b/NEWS.md index b29937a5d..dddec2591 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ * Added support for internal validation tasks to `PipeOpFeatureUnion`. * feat: `PipeOpLearnerCV` can reuse the cross-validation models during prediction by averaging their outputs (`resampling.predict_method = "cv_ensemble"`). * feat: `PipeOpRegrAvg` gets new `se_aggr` and `se_aggr_rho` hyperparameters and now allows various forms of SE aggregation. +* Fix: `PipeOpRemoveConstants` now avoids integer overflow when evaluating relative tolerances for near-`integer.max` data. * Compatibility with new testthat version 3.3.0 # mlr3pipelines 0.9.0 diff --git a/R/PipeOpRemoveConstants.R b/R/PipeOpRemoveConstants.R index f6237a431..ecaaa6c44 100644 --- a/R/PipeOpRemoveConstants.R +++ b/R/PipeOpRemoveConstants.R @@ -109,7 +109,7 @@ is_constant_enough = function(x, ratio, rel_tol, abs_tol, na_ignore) { # now consider finite values: sort them and see if items that are # 'required_size - 1' steps away from each other differ by at most 'abs_tol' or 'rel_tol' - x = sort(x[is.finite(x)]) + x = as.numeric(sort(x[is.finite(x)])) if (length(x) < required_size) { return(FALSE) } diff --git a/tests/testthat/test_pipeop_removeconstants.R b/tests/testthat/test_pipeop_removeconstants.R index 1e596e031..faeeeec9c 100644 --- a/tests/testthat/test_pipeop_removeconstants.R +++ b/tests/testthat/test_pipeop_removeconstants.R @@ -70,3 +70,19 @@ test_that("PipeOpRemoveConstants removes expected cols", { test_dropping(minus.iris , minus.iris, list()) }) + +test_that("PipeOpRemoveConstants handles integer overflow constants", { + n = 5L + big = .Machine$integer.max + dt = data.table( + const = c(rep.int(big, n - 1L), big - 1L), + vary = c(big, big - 10L, big - 20L, big - 30L, big - 40L), + target = factor(c("a", "a", "b", "b", "b")) + ) + + task = TaskClassif$new("overflow", dt, target = "target") + po = PipeOpRemoveConstants$new(param_vals = list(abs_tol = 0)) + + result = po$train(list(task))[[1]] + expect_false("const" %in% result$feature_names) +})