Skip to content

Commit

Permalink
tests: properties
Browse files Browse the repository at this point in the history
  • Loading branch information
be-marc committed Sep 6, 2024
1 parent 1c05bcd commit b643f5c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions R/Learner.R
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ Learner = R6Class("Learner",
fallback$id, self$id, fallback$predict_type, self$predict_type)
}

# check properties
properties = intersect(self$properties, c("twoclass", "multiclass", "missings", "importance", "selected_features"))
missing_properties = setdiff(properties, fallback$properties)

if (length(missing_properties)) {
warningf("The fallback learner '%s' does not have the following properties of the learner '%s': %s.",
fallback$id, self$id, str_collapse(missing_properties))
}

# check properties
} else if (method == "none" && !is.null(fallback)) {
stop("Fallback learner must be NULL if encapsulation is deactivated.")
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_errorhandling.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ test_that("encapsulation / benchmark", {
expect_equal(aggr$warnings, 3L)
expect_equal(aggr$errors, 3L)
})

7 changes: 7 additions & 0 deletions tests/testthat/test_fallback.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,10 @@ test_that("incomplete predictions", {
expect_factor(rr$prediction()$response, any.missing = FALSE)
expect_matrix(rr$prediction()$prob, any.missing = FALSE)
})

test_that("fallback properties are checked", {
learner = lrn("classif.featureless")
fallback = lrn("classif.debug")

expect_warning(learner$encapsulate("evaluate", fallback), "The fallback learner")
})

0 comments on commit b643f5c

Please sign in to comment.