Skip to content

Commit

Permalink
feat(check): better error message when measure's minimize is NA (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebffischer authored Jan 13, 2025
1 parent 9a5a587 commit 535c418
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions R/helper.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
measures_to_codomain = function(measures) {
measures = as_measures(measures)
domains = map(measures, function(s) {
if (is.na(s$minimize)) {
stopf("Measure %s has its `minimize` field set to NA, which is disallowed when tuning.", s$id)
}
p_dbl(tags = ifelse(s$minimize, "minimize", "maximize"))
})
names(domains) = ids(measures)
Expand Down
1 change: 1 addition & 0 deletions man/AutoTuner.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/mlr_tuners_cmaes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat/test_Tuner.R
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,15 @@ test_that("Can only pass internal tune tokens one way", {
term_evals = 2),
"Either tag parameters")
})

test_that("Correct error when minimize is NA", {
m = msr("classif.acc")
m$minimize = NA
expect_error(tune(
tuner = tnr("random_search"),
task = tsk("iris"),
learner = lrn("classif.debug", x = to_tune()),
resampling = rsmp("holdout"),
measure = m
), "`minimize`")
})

0 comments on commit 535c418

Please sign in to comment.