From c833e90750b680a3b3475f9d858d26398d060a1f Mon Sep 17 00:00:00 2001 From: topepo Date: Wed, 28 Aug 2024 13:37:32 -0400 Subject: [PATCH] testing and snapshot updates for tidymodels/parsnip#1162 --- tests/testthat/_snaps/glmnet-linear.md | 2 +- tests/testthat/_snaps/glmnet-logistic.md | 2 +- tests/testthat/_snaps/glmnet-multinom.md | 2 +- tests/testthat/_snaps/parsnip-case-weights.md | 46 +++++++++++++++++++ .../parsnip-survival-censoring-model.md | 2 +- .../parsnip-survival-censoring-weights.md | 12 ++--- .../_snaps/parsnip-survival-standalone.md | 6 +-- .../recipes1.1.0/recipes-nnmf_sparse.md | 36 +++++++++++++++ tests/testthat/test-glmnet-linear.R | 2 +- tests/testthat/test-glmnet-logistic.R | 2 +- tests/testthat/test-glmnet-multinom.R | 2 +- .../test-parsnip-survival-censoring-weights.R | 4 +- 12 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 tests/testthat/_snaps/parsnip-case-weights.md create mode 100644 tests/testthat/_snaps/recipes1.1.0/recipes-nnmf_sparse.md diff --git a/tests/testthat/_snaps/glmnet-linear.md b/tests/testthat/_snaps/glmnet-linear.md index b3a14e94..950ada48 100644 --- a/tests/testthat/_snaps/glmnet-linear.md +++ b/tests/testthat/_snaps/glmnet-linear.md @@ -25,6 +25,6 @@ linear_reg(penalty = 0.01) %>% set_engine("glmnet") %>% fit(mpg ~ ., data = mtcars) %>% multi_predict(mtcars, type = "class") Condition - Error in `check_pred_type()`: + Error in `multi_predict()`: ! For class predictions, the object should be a classification model. diff --git a/tests/testthat/_snaps/glmnet-logistic.md b/tests/testthat/_snaps/glmnet-logistic.md index 0840124a..a9408d92 100644 --- a/tests/testthat/_snaps/glmnet-logistic.md +++ b/tests/testthat/_snaps/glmnet-logistic.md @@ -36,6 +36,6 @@ funded_amnt) + int_rate + term, data = lending_club) %>% multi_predict( lending_club, type = "time") Condition - Error in `check_pred_type()`: + Error in `multi_predict()`: ! For event time predictions, the object should be a censored regression. diff --git a/tests/testthat/_snaps/glmnet-multinom.md b/tests/testthat/_snaps/glmnet-multinom.md index 8f3f5ca7..bb06bfcc 100644 --- a/tests/testthat/_snaps/glmnet-multinom.md +++ b/tests/testthat/_snaps/glmnet-multinom.md @@ -33,6 +33,6 @@ multinom_reg(penalty = 0.01) %>% set_engine("glmnet") %>% fit(class ~ ., data = hpc_data) %>% multi_predict(hpc_data, type = "numeric") Condition - Error in `check_pred_type()`: + Error in `multi_predict()`: ! For numeric predictions, the object should be a regression model. diff --git a/tests/testthat/_snaps/parsnip-case-weights.md b/tests/testthat/_snaps/parsnip-case-weights.md new file mode 100644 index 00000000..514109c6 --- /dev/null +++ b/tests/testthat/_snaps/parsnip-case-weights.md @@ -0,0 +1,46 @@ +# boost_tree - xgboost case weights + + Code + print(wt_fit$fit$call) + Output + xgboost::xgb.train(params = list(eta = 0.3, max_depth = 6, gamma = 0, + colsample_bytree = 1, colsample_bynode = 1, min_child_weight = 1, + subsample = 1), data = x$data, nrounds = 15, watchlist = x$watchlist, + verbose = 0, nthread = 1, objective = "binary:logistic") + +# decision_tree - rpart case weights + + Code + print(wt_fit$fit$call) + Output + rpart::rpart(formula = Class ~ ., data = data, weights = weights) + +# logistic_reg - stan case weights + + Code + print(wt_fit$fit$call) + Output + rstanarm::stan_glm(formula = Class ~ ., family = stats::binomial, + data = data, weights = weights, seed = ~1, refresh = 0) + +# mars - earth case weights + + Code + print(wt_fit$fit$call) + Output + earth(formula = Class ~ ., data = data, weights = weights, keepxy = TRUE, + glm = ~list(family = stats::binomial)) + +# mlp - nnet case weights + + Case weights are not enabled by the underlying model implementation. + +# rand_forest - ranger case weights + + Code + print(wt_fit$fit$call) + Output + ranger::ranger(x = maybe_data_frame(x), y = y, num.threads = 1, + verbose = FALSE, seed = sample.int(10^5, 1), probability = TRUE, + case.weights = weights) + diff --git a/tests/testthat/_snaps/parsnip-survival-censoring-model.md b/tests/testthat/_snaps/parsnip-survival-censoring-model.md index 903474e2..8f882d18 100644 --- a/tests/testthat/_snaps/parsnip-survival-censoring-model.md +++ b/tests/testthat/_snaps/parsnip-survival-censoring-model.md @@ -21,5 +21,5 @@ predict(alt_obj, time = 100) Condition Error in `predict()`: - ! Don't know how to predict with a censoring model of type: reverse_km + ! Don't know how to predict with a censoring model of type reverse_km. diff --git a/tests/testthat/_snaps/parsnip-survival-censoring-weights.md b/tests/testthat/_snaps/parsnip-survival-censoring-weights.md index 8ba79a25..92c055fb 100644 --- a/tests/testthat/_snaps/parsnip-survival-censoring-weights.md +++ b/tests/testthat/_snaps/parsnip-survival-censoring-weights.md @@ -4,7 +4,7 @@ .censoring_weights_graf("nothing useful") Condition Error in `.censoring_weights_graf()`: - ! There is no `.censoring_weights_graf()` method for objects with class(es): 'character' + ! There is no `.censoring_weights_graf()` method for objects with class . --- @@ -12,7 +12,7 @@ .censoring_weights_graf(cox_model, lung) Condition Error: - ! There should be a single column of class `Surv` + ! There should be a single column of class . --- @@ -22,7 +22,7 @@ .censoring_weights_graf(cox_model, lung_left) Condition Error in `.censoring_weights_graf()`: - ! For this usage, the allowed censoring type is: 'right' + ! For this usage, the allowed censoring type is right. --- @@ -30,7 +30,7 @@ .censoring_weights_graf(cox_model, lung2) Condition Error: - ! The input should have a list column called `.pred`. + ! The input should have a list column called ".pred". --- @@ -38,7 +38,7 @@ .censoring_weights_graf(cox_model, preds, cens_predictors = "shouldn't be using this anyway!") Condition Warning: - The 'cens_predictors' argument to the survival weighting function is not currently used. + `cens_predictors` is not currently used. Output # A tibble: 3 x 2 .pred surv @@ -60,6 +60,6 @@ Code .censoring_weights_graf(wrong_model, mtcars) Condition - Error in `.check_censor_model()`: + Error in `.censoring_weights_graf()`: ! The model needs to be for mode 'censored regression', not for mode 'regression'. diff --git a/tests/testthat/_snaps/parsnip-survival-standalone.md b/tests/testthat/_snaps/parsnip-survival-standalone.md index 8e941ebb..c3c8abad 100644 --- a/tests/testthat/_snaps/parsnip-survival-standalone.md +++ b/tests/testthat/_snaps/parsnip-survival-standalone.md @@ -4,7 +4,7 @@ parsnip:::.is_surv(1) Condition Error: - ! The object does not have class `Surv`. + ! The object does not have class . # .check_cens_type() @@ -12,7 +12,7 @@ parsnip:::.check_cens_type(left_c, type = "right", fail = TRUE) Condition Error: - ! For this usage, the allowed censoring type is: 'right' + ! For this usage, the allowed censoring type is right. --- @@ -20,5 +20,5 @@ parsnip:::.check_cens_type(left_c, type = c("right", "interval"), fail = TRUE) Condition Error: - ! For this usage, the allowed censoring types are: 'right' and 'interval' + ! For this usage, the allowed censoring types are right or interval. diff --git a/tests/testthat/_snaps/recipes1.1.0/recipes-nnmf_sparse.md b/tests/testthat/_snaps/recipes1.1.0/recipes-nnmf_sparse.md new file mode 100644 index 00000000..f47bed4c --- /dev/null +++ b/tests/testthat/_snaps/recipes1.1.0/recipes-nnmf_sparse.md @@ -0,0 +1,36 @@ +# Correct values + + Code + print(rec) + Message + + -- Recipe ---------------------------------------------------------------------- + + -- Inputs + Number of variables by role + outcome: 1 + predictor: 4 + + -- Operations + * Non-negative matrix factorization for: all_predictors() + +# No NNF + + Code + print(rec) + Message + + -- Recipe ---------------------------------------------------------------------- + + -- Inputs + Number of variables by role + outcome: 1 + predictor: 4 + + -- Training information + Training data contained 150 data points and no incomplete rows. + + -- Operations + * No non-negative matrix factorization was extracted from: Sepal.Length, + Sepal.Width, Petal.Length, Petal.Width | Trained + diff --git a/tests/testthat/test-glmnet-linear.R b/tests/testthat/test-glmnet-linear.R index 26bac500..d8e177c3 100644 --- a/tests/testthat/test-glmnet-linear.R +++ b/tests/testthat/test-glmnet-linear.R @@ -265,7 +265,7 @@ test_that('multi_predict() with default or single penalty value', { test_that('error traps', { skip_if_not_installed("glmnet") - skip_if_not_installed("parsnip", minimum_version = "1.2.1.9001") + skip_if_not_installed("parsnip", minimum_version = "1.2.1.9002") expect_snapshot(error = TRUE, { linear_reg(penalty = 0.01) %>% diff --git a/tests/testthat/test-glmnet-logistic.R b/tests/testthat/test-glmnet-logistic.R index 2be46e8e..52336b08 100644 --- a/tests/testthat/test-glmnet-logistic.R +++ b/tests/testthat/test-glmnet-logistic.R @@ -377,7 +377,7 @@ test_that("class predictions are factors with all levels", { test_that('error traps', { skip_if_not_installed("glmnet") - skip_if_not_installed("parsnip", minimum_version = "1.2.1.9001") + skip_if_not_installed("parsnip", minimum_version = "1.2.1.9002") data("lending_club", package = "modeldata", envir = rlang::current_env()) diff --git a/tests/testthat/test-glmnet-multinom.R b/tests/testthat/test-glmnet-multinom.R index 5dea6a2c..8b7f7197 100644 --- a/tests/testthat/test-glmnet-multinom.R +++ b/tests/testthat/test-glmnet-multinom.R @@ -399,7 +399,7 @@ test_that("class predictions are factors with all levels", { test_that('error traps', { skip_if_not_installed("glmnet") - skip_if_not_installed("parsnip", minimum_version = "1.2.1.9001") + skip_if_not_installed("parsnip", minimum_version = "1.2.1.9002") data("hpc_data", package = "modeldata", envir = rlang::current_env()) diff --git a/tests/testthat/test-parsnip-survival-censoring-weights.R b/tests/testthat/test-parsnip-survival-censoring-weights.R index b3aba3d1..d9b3ab51 100644 --- a/tests/testthat/test-parsnip-survival-censoring-weights.R +++ b/tests/testthat/test-parsnip-survival-censoring-weights.R @@ -174,6 +174,8 @@ test_that('compute Graf weights', { }) test_that("error messages in context of .censoring_weights_graf()", { + skip_if_not_installed("parsnip", minimum_version = "1.2.1.9002") + lung2 <- lung %>% dplyr::mutate(surv = Surv(time, status), .keep = "unused") @@ -228,7 +230,7 @@ test_that("error for .censoring_weights_graf.workflow()", { test_that("error for .censoring_weights_graf() from .check_censor_model()", { # temporarily its own test, see above - skip_if_not_installed("parsnip", minimum_version = "1.1.0.9003") + skip_if_not_installed("parsnip", minimum_version = "1.2.1.9002") wrong_model <- fit(linear_reg(), mpg ~ ., data = mtcars) expect_snapshot(error = TRUE, .censoring_weights_graf(wrong_model, mtcars)) })