Skip to content

Commit e9eccb7

Browse files
re-enable some skipped tests (#1093)
* fit a glmnet model with a real penalty * rework test * skips no longer needed * add a few installs * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * air format * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 9c28a4f commit e9eccb7

File tree

4 files changed

+76
-47
lines changed

4 files changed

+76
-47
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ jobs:
5656
extra-packages: any::rcmdcheck
5757
needs: check
5858

59+
- name: Try to install a few packages for testing
60+
run: |
61+
# from most dependency-heavy to least
62+
try(pak::pkg_install(c(
63+
"randomForest",
64+
"glmnet"
65+
)))
66+
shell: Rscript {0}
67+
5968
- uses: r-lib/actions/check-r-package@v2
6069
with:
6170
upload-snapshots: true

tests/testthat/test-bayes.R

Lines changed: 61 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ test_that("tune model and recipe (multi-predict)", {
283283
# ------------------------------------------------------------------------------
284284

285285
test_that("tune recipe only - failure in recipe is caught elegantly", {
286-
skip("test is not implemented for tune_bayes()")
287286
skip_if_not_installed("splines2")
288287

289288
# With tune_grid() this tests for NA values in the grid.
@@ -301,36 +300,47 @@ test_that("tune recipe only - failure in recipe is caught elegantly", {
301300
# NA values not allowed in recipe
302301
cars_grid <- tibble(deg_free = c(3, NA_real_, 4))
303302

304-
# ask for predictions and extractions
305-
control <- control_bayes(
306-
save_pred = TRUE,
307-
extract = function(x) 1L
308-
)
309-
310303
suppressMessages({
311-
cars_res <- tune_bayes(
304+
cars_init_res <- tune_grid(
312305
model,
313306
preprocessor = rec,
314307
resamples = data_folds,
315-
control = control
308+
grid = cars_grid
316309
)
317310
})
318311

319-
notes <- cars_res$.notes
320-
note <- notes[[1]]$note
312+
suppressMessages({
313+
set.seed(283) #<- chosen to not generate faiures
314+
cars_bayes_res <- tune_bayes(
315+
model,
316+
preprocessor = rec,
317+
resamples = data_folds,
318+
initial = cars_init_res,
319+
iter = 2
320+
)
321+
})
321322

322-
extract <- cars_res$.extracts[[1]]
323+
exp_failures <- nrow(data_folds) * sum(!complete.cases(cars_grid))
324+
obs_init_failures <- collect_notes(cars_init_res) |>
325+
filter(type == "error") |>
326+
nrow()
327+
obs_failures <- collect_notes(cars_bayes_res) |>
328+
filter(type == "error") |>
329+
nrow()
323330

324-
predictions <- cars_res$.predictions[[1]]
325-
used_deg_free <- sort(unique(predictions$deg_free))
331+
exp_init_grid_res <-
332+
cars_grid |> tidyr::drop_na() |> distinct(deg_free) |> nrow()
326333

327-
expect_length(notes, 2L)
334+
expect_equal(obs_init_failures, obs_failures)
335+
expect_equal(obs_failures, exp_failures)
328336

329-
# failing rows are not in the output
330-
expect_equal(nrow(extract), 2L)
331-
expect_equal(extract$deg_free, c(3, 4))
337+
all_notes <- collect_notes(cars_bayes_res)
338+
expect_equal(nrow(all_notes), 11L)
332339

333-
expect_equal(used_deg_free, c(3, 4))
340+
expect_equal(
341+
collect_metrics(cars_bayes_res) |> distinct(deg_free) |> nrow(),
342+
exp_init_grid_res + 2
343+
)
334344
})
335345

336346
test_that("tune model only - failure in recipe is caught elegantly", {
@@ -397,38 +407,51 @@ test_that("tune model and recipe - failure in recipe is caught elegantly", {
397407
recipes::step_spline_b(disp, deg_free = tune())
398408

399409
# NA values not allowed in recipe
400-
cars_grid <- tibble(deg_free = c(NA_real_, 10L), cost = 0.01)
410+
cars_grid <- tibble(
411+
deg_free = c(3L, NA_real_, 10L),
412+
cost = c(0.1, 0.01, 0.001)
413+
)
401414

402415
suppressMessages({
403-
cars_res <- tune_bayes(
416+
cars_init_res <- tune_grid(
404417
svm_mod,
405418
preprocessor = rec,
406419
resamples = data_folds,
407-
control = control_bayes(
408-
extract = function(x) {
409-
1
410-
},
411-
save_pred = TRUE
412-
)
420+
grid = cars_grid
421+
)
422+
})
423+
424+
suppressMessages({
425+
set.seed(283) #<- chosen to not generate faiures
426+
cars_bayes_res <- tune_bayes(
427+
svm_mod,
428+
preprocessor = rec,
429+
resamples = data_folds,
430+
initial = cars_init_res,
431+
iter = 2
413432
)
414433
})
415434

416-
notes <- cars_res$.notes
417-
note <- notes[[1]]$note
435+
exp_failures <- nrow(data_folds) * sum(!complete.cases(cars_grid))
436+
obs_init_failures <- collect_notes(cars_init_res) |>
437+
filter(type == "error") |>
438+
nrow()
439+
obs_failures <- collect_notes(cars_bayes_res) |>
440+
filter(type == "error") |>
441+
nrow()
418442

419-
extract <- cars_res$.extracts[[1]]
420-
prediction <- cars_res$.predictions[[1]]
443+
exp_init_grid_res <-
444+
cars_grid |> tidyr::drop_na() |> distinct(deg_free, cost) |> nrow()
421445

422-
expect_length(notes, 2L)
446+
expect_equal(obs_init_failures, obs_failures)
447+
expect_equal(obs_failures, exp_failures)
423448

424-
# recipe failed half of the time, only 1 model passed
425-
expect_equal(nrow(extract), 1L)
426-
expect_equal(extract$deg_free, 10L)
427-
expect_equal(extract$cost, 0.01)
449+
all_notes <- collect_notes(cars_bayes_res)
450+
expect_equal(nrow(all_notes), 6L)
428451

429452
expect_equal(
430-
unique(prediction[, c("deg_free", "cost")]),
431-
tibble(deg_free = 10, cost = 0.01)
453+
collect_metrics(cars_bayes_res) |> distinct(deg_free, cost) |> nrow(),
454+
exp_init_grid_res + 2
432455
)
433456
})
434457

tests/testthat/test-last-fit.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ test_that("argument order gives errors for recipe/formula", {
129129

130130
test_that("same results of last_fit() and fit() (#300)", {
131131
skip_if_not_installed("randomForest")
132-
skip("determine how to handle this with parallel seeds; maybe opt out?")
133132

134133
rf <- parsnip::rand_forest(mtry = 2, trees = 5) |>
135134
parsnip::set_engine("randomForest") |>
@@ -250,7 +249,6 @@ test_that("can use `last_fit()` with a workflow - postprocessor (requires traini
250249
skip_if_not_installed("mgcv")
251250
skip_if_not_installed("tailor", minimum_version = "0.0.0.9002")
252251
skip_if_not_installed("probably")
253-
skip("work on how to make internal_calibration_split reproducible")
254252

255253
y <- seq(0, 7, .001)
256254
dat <- data.frame(y = y, x = y + (y - 3)^2)

tests/testthat/test-loop-over-all-stages-helpers-predict-all-types.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,6 @@ test_that("predict censored regression - submodels - no calibration", {
10561056
skip_if_not_installed("survival")
10571057
skip_if_not_installed("glmnet")
10581058

1059-
skip("not working")
1060-
10611059
library(censored)
10621060

10631061
cens <- make_post_data(mode = "censored")
@@ -1068,7 +1066,7 @@ test_that("predict censored regression - submodels - no calibration", {
10681066
glmn_cens <- proportional_hazards(penalty = tune()) |> set_engine("glmnet")
10691067

10701068
wflow <- workflow(pca_rec, glmn_cens)
1071-
wflow_fit <- fit(wflow, cens$data)
1069+
10721070
grd <-
10731071
wflow |>
10741072
extract_parameter_set_dials() |>
@@ -1089,6 +1087,11 @@ test_that("predict censored regression - submodels - no calibration", {
10891087

10901088
ctrl <- tune::control_grid()
10911089

1090+
wflow_fit <-
1091+
wflow |>
1092+
finalize_workflow(grd[1, ]) |>
1093+
fit(cens$data)
1094+
10921095
# ----------------------------------------------------------------------------
10931096
# static metrics
10941097

@@ -1105,10 +1108,6 @@ test_that("predict censored regression - submodels - no calibration", {
11051108
static_stc <- tune:::update_static(static_stc, data_1)
11061109
static_stc$y_name <- "outcome"
11071110

1108-
# TODO error
1109-
# Error in lambda[1] - s : non-numeric argument to binary operator
1110-
# Called from: lambda.interp(lambda, s)
1111-
11121111
res_stc <- tune:::predict_all_types(
11131112
wflow_fit,
11141113
static_stc,

0 commit comments

Comments
 (0)