Skip to content

Commit

Permalink
chore: add hint that resampling could be instantiated on a different …
Browse files Browse the repository at this point in the history
…task (#1200)
  • Loading branch information
be-marc authored Nov 5, 2024
1 parent 0c46b69 commit ea53d4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/Task.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test_resample.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

})

0 comments on commit ea53d4a

Please sign in to comment.