Skip to content

Commit

Permalink
Changes for #962
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo committed Nov 13, 2024
1 parent f85eac9 commit 420ccbb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 6 additions & 1 deletion R/tune_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,12 @@ create_initial_set <- function(param, n = NULL, checks) {
if (any(checks == "bayes")) {
check_bayes_initial_size(nrow(param), n)
}
dials::grid_space_filling(param, size = n)
if (n == 1) {
res <- dials::grid_random(param, size = n)
} else {
res <- dials::grid_space_filling(param, size = n)
}
res
}

check_iter <- function(iter, call) {
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/_snaps/bayes.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@
Message
x Fold1: preprocessor 1/1:
Error in `step_spline_b()`:
Caused by error in `spline_msg()`:
! Error in if (df < 0) : missing value where TRUE/FALSE needed
Caused by error in `prep()`:
! `deg_free` must be a whole number, not a numeric `NA`.
x Fold2: preprocessor 1/1:
Error in `step_spline_b()`:
Caused by error in `spline_msg()`:
! Error in if (df < 0) : missing value where TRUE/FALSE needed
Caused by error in `prep()`:
! `deg_free` must be a whole number, not a numeric `NA`.
Condition
Warning:
All models failed. Run `show_notes(.Last.tune.result)` for more information.
Expand All @@ -415,10 +415,10 @@
Message
x Fold1: preprocessor 1/1:
Error in `get_all_predictors()`:
! The following predictors were not found in `data`: 'z'.
! The following predictor was not found in `data`: "z".
x Fold2: preprocessor 1/1:
Error in `get_all_predictors()`:
! The following predictors were not found in `data`: 'z'.
! The following predictor was not found in `data`: "z".
Condition
Warning:
All models failed. Run `show_notes(.Last.tune.result)` for more information.
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,19 @@ test_that("tune_bayes() output for `iter` edge cases (#721)", {
tune_bayes(wf, boots, iter = NULL)
)
})

test_that("1-point grid (#962)", {
skip_if_not_installed("dials", minimum_version = "1.3.0")

expect_silent({
set.seed(1)
grid <- tune:::create_initial_set(
dials::parameters(dials::penalty(), dials::deg_free()),
n = 1,
checks = "none"
)
})
expect_equal(nrow(grid), 1L)
})


0 comments on commit 420ccbb

Please sign in to comment.