Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on NULL engine #1248

Merged
merged 7 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

* The quantile regression prediction type was disabled for the deprecated `surv_reg()` model.

* `NULL` is no longer accepted as an engine (#1242).


# parsnip 1.2.1

Expand Down
2 changes: 1 addition & 1 deletion R/engines.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ set_engine <- function(object, engine, ...) {
set_engine.model_spec <- function(object, engine, ...) {
mod_type <- class(object)[1]

if (rlang::is_missing(engine)) {
if (rlang::is_missing(engine) || is.null(engine)) {
stop_missing_engine(mod_type, call = caller_env(0))
}
object$engine <- engine
Expand Down
2 changes: 1 addition & 1 deletion man/details_linear_reg_glmer.Rd

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

2 changes: 1 addition & 1 deletion man/details_linear_reg_lmer.Rd

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

2 changes: 1 addition & 1 deletion man/details_linear_reg_stan_glmer.Rd

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

2 changes: 1 addition & 1 deletion man/details_logistic_reg_glmer.Rd

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

2 changes: 1 addition & 1 deletion man/details_logistic_reg_stan_glmer.Rd

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

2 changes: 1 addition & 1 deletion man/details_poisson_reg_glmer.Rd

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

2 changes: 1 addition & 1 deletion man/details_poisson_reg_stan_glmer.Rd

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

2 changes: 1 addition & 1 deletion man/parsnip-package.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/engines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# NULL engines

Code
set_engine(nearest_neighbor(), NULL)
Condition
Error in `set_engine()`:
! Missing engine. Possible mode/engine combinations are: classification {kknn} and regression {kknn}.

3 changes: 1 addition & 2 deletions tests/testthat/_snaps/mlp_keras.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
Class ~ A + B, data = modeldata::two_class_dat)
Condition
Error in `parsnip::keras_mlp()`:
! `activation` should be one of: elu, exponential, gelu, hardsigmoid, linear, relu, selu, sigmoid, softmax, softplus, softsign, swish, and tanh, not "invalid".

! `activation` should be one of: elu, exponential, gelu, hard_sigmoid, linear, relu, selu, sigmoid, softmax, softplus, softsign, swish, and tanh, not "invalid".
5 changes: 3 additions & 2 deletions tests/testthat/_snaps/rand_forest.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

Code
res <- translate(rand_forest(mode = "classification") %>% set_engine(NULL))
Message
Used `engine = 'ranger'` for translation.
Condition
Error in `set_engine()`:
! Missing engine. Possible mode/engine combinations are: classification {ranger, randomForest, spark} and regression {ranger, randomForest, spark}.

---

Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/_snaps/surv_reg.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@

Code
res <- translate(surv_reg() %>% set_engine(NULL))
Message
Used `engine = 'survival'` for translation.
Condition
Error in `set_engine()`:
! Missing engine. Possible mode/engine combinations are: regression {flexsurv, survival}.

# deprecation warning

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/svm_linear.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
Code
translate(svm_linear(mode = "regression") %>% set_engine(NULL))
Condition
Error in `translate.default()`:
! Please set an engine.
Error in `set_engine()`:
! Missing engine. Possible mode/engine combinations are: classification {LiblineaR, kernlab} and regression {LiblineaR, kernlab}.

---

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/svm_poly.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
Code
svm_poly() %>% set_engine(NULL) %>% translate()
Condition
Error in `translate.default()`:
! Please set an engine.
Error in `set_engine()`:
! Missing engine. Possible mode/engine combinations are: classification {kernlab} and regression {kernlab}.

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/svm_rbf.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
Code
translate(svm_rbf(mode = "regression") %>% set_engine(NULL))
Condition
Error in `translate.default()`:
! Please set an engine.
Error in `set_engine()`:
! Missing engine. Possible mode/engine combinations are: classification {kernlab, liquidSVM} and regression {kernlab, liquidSVM}.

8 changes: 8 additions & 0 deletions tests/testthat/test-engines.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test_that("NULL engines", {
# See issue https://github.com/tidymodels/parsnip/issues/1242

expect_snapshot(
set_engine(nearest_neighbor(), NULL),
error = TRUE
)
})
1 change: 1 addition & 0 deletions tests/testthat/test-mlp_keras.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ test_that('all keras activation functions', {
skip_on_cran()
skip_if_not_installed("keras")
skip_if_not_installed("modeldata")
skip_if_not_installed("dials", minimum_version = "1.3.0.9000")
skip_if(!is_tf_ok())

act <- parsnip:::keras_activations()
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-rand_forest.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ test_that('updating', {
})

test_that('bad input', {
expect_snapshot(res <- translate(rand_forest(mode = "classification") %>% set_engine(NULL)))
expect_snapshot(res <-
translate(rand_forest(mode = "classification") %>%
set_engine(NULL)),
error = TRUE)
expect_snapshot(error = TRUE, rand_forest(mode = "time series"))
expect_snapshot(error = TRUE, translate(rand_forest(mode = "classification") %>% set_engine("wat?")))
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-surv_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_that('bad input', {

expect_snapshot(error = TRUE, surv_reg(mode = ", classification"))
expect_snapshot(error = TRUE, translate(surv_reg() %>% set_engine("wat")))
expect_snapshot(res <- translate(surv_reg() %>% set_engine(NULL)))
expect_snapshot(res <- translate(surv_reg() %>% set_engine(NULL)), error = TRUE)
})

test_that("deprecation warning", {
Expand Down
Loading