diff --git a/R/Task.R b/R/Task.R index da439e3ec..60dfa2a52 100644 --- a/R/Task.R +++ b/R/Task.R @@ -305,7 +305,8 @@ Task = R6Class("Task", data = self$backend$data(rows = rows, cols = query_cols) if (length(query_cols) && nrow(data) != length(rows)) { - stopf("DataBackend did not return the queried rows correctly: %i requested, %i received", length(rows), nrow(data)) + stopf("DataBackend did not return the queried rows correctly: %i requested, %i received. + The resampling was probably instantiated on a different task.", length(rows), nrow(data)) } if (length(rows) && ncol(data) != length(query_cols)) { diff --git a/tests/testthat/test_resample.R b/tests/testthat/test_resample.R index 3c6f90457..27bbd7b27 100644 --- a/tests/testthat/test_resample.R +++ b/tests/testthat/test_resample.R @@ -512,3 +512,11 @@ test_that("predict_time is 0 if no predict_set is specified", { expect_true(all(times == 0)) }) +test_that("resampling instantiated on a different task throws an error", { + task = tsk("spam") + resampling = rsmp("cv", folds = 3) + resampling$instantiate(task) + + expect_error(resample(tsk("pima"), lrn("classif.rpart"), resampling), "The resampling was probably instantiated on a different task") + +})