From 9f8c862482ffb6dfc508a59b839a7a93c3340d1f Mon Sep 17 00:00:00 2001 From: Sebastian Fischer Date: Tue, 3 Sep 2024 10:58:35 +0200 Subject: [PATCH] fix(prediction): predict_time for no predictions --- R/worker.R | 4 ++++ tests/testthat/test_resample.R | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/R/worker.R b/R/worker.R index 3ee363ebc..f147adbeb 100644 --- a/R/worker.R +++ b/R/worker.R @@ -326,6 +326,10 @@ workhorse = function(iteration, task, learner, resampling, param_values = NULL, lg$debug("Creating Prediction for predict set '%s'", set) learner_predict(learner, task, row_ids) }, set = predict_sets, row_ids = pred_data$sets, task = pred_data$tasks) + + if (!length(predict_sets)) { + learner$state$predict_time = 0L + } pdatas = discard(pdatas, is.null) # set the model slot after prediction so it can be sent back to the main process diff --git a/tests/testthat/test_resample.R b/tests/testthat/test_resample.R index 35a2a5afa..47e0bbceb 100644 --- a/tests/testthat/test_resample.R +++ b/tests/testthat/test_resample.R @@ -490,3 +490,10 @@ test_that("resample results works with no predicted predict set", { expect_list(tab$prediction, len = 1) expect_list(tab$prediction[[1]], len = 0) }) + +test_that("predict_time is 0 if no predict_set is specified", { + learner = lrn("classif.featureless", predict_sets = NULL) + rr = resample(task, learner, resampling) + times = rr$score(msr("time_predict"))$time_predict + expect_true(all(times == 0)) +})