Skip to content

Commit 9a44b32

Browse files
committed
expect_warning() -> expect_snapshot()
1 parent 1f48072 commit 9a44b32

20 files changed

+234
-31
lines changed

tests/testthat/_snaps/boost_tree_C5.0.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,21 @@
1515
Error in `multi_predict()`:
1616
! Please use `new_data` instead of `newdata`.
1717

18+
# argument checks for data dimensions
19+
20+
Code
21+
f_fit <- spec %>% fit(species ~ ., data = penguins)
22+
Condition
23+
Warning:
24+
! 1000 samples were requested but there were 333 rows in the data.
25+
i 333 will be used.
26+
27+
---
28+
29+
Code
30+
xy_fit <- spec %>% fit_xy(x = penguins[, -1], y = penguins$species)
31+
Condition
32+
Warning:
33+
! 1000 samples were requested but there were 333 rows in the data.
34+
i 333 will be used.
35+

tests/testthat/_snaps/boost_tree_xgboost.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434

3535
# early stopping
3636

37+
Code
38+
reg_fit <- boost_tree(trees = 20, stop_iter = 30, mode = "regression") %>%
39+
set_engine("xgboost", validation = 0.1) %>% fit(mpg ~ ., data = mtcars[-(1:4),
40+
])
41+
Condition
42+
Warning:
43+
`early_stop` was reduced to 19.
44+
45+
---
46+
3747
Code
3848
reg_fit <- boost_tree(trees = 20, stop_iter = 0, mode = "regression") %>%
3949
set_engine("xgboost", validation = 0.1) %>% fit(mpg ~ ., data = mtcars[-(1:4),
@@ -50,6 +60,24 @@
5060
Warning:
5161
`event_level` can only be set for binary outcomes.
5262

63+
# argument checks for data dimensions
64+
65+
Code
66+
f_fit <- spec %>% fit(species ~ ., data = penguins, control = ctrl)
67+
Condition
68+
Warning:
69+
! 1000 samples were requested but there were 333 rows in the data.
70+
i 333 will be used.
71+
72+
---
73+
74+
Code
75+
xy_fit <- spec %>% fit_xy(x = penguins_dummy, y = penguins$species, control = ctrl)
76+
Condition
77+
Warning:
78+
! 1000 samples were requested but there were 333 rows in the data.
79+
i 333 will be used.
80+
5381
# count/proportion parameters
5482

5583
Code

tests/testthat/_snaps/convert_data.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
Error in `na.fail.default()`:
88
! missing values in object
99

10+
# numeric x and factor y
11+
12+
Code
13+
expected <- glm(class ~ ., data = hpc, x = TRUE, y = TRUE, family = binomial())
14+
Condition
15+
Warning:
16+
glm.fit: fitted probabilities numerically 0 or 1 occurred
17+
1018
# bad args
1119

1220
Code
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# numeric model
2+
3+
Code
4+
num_res <- predict(lm_mod, hpc_bad[1:11, -1])
5+
Condition
6+
Warning:
7+
Model fit failed; cannot make predictions.
8+
9+
---
10+
11+
Code
12+
ci_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "conf_int")
13+
Condition
14+
Warning:
15+
Model fit failed; cannot make predictions.
16+
17+
---
18+
19+
Code
20+
pi_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "pred_int")
21+
Condition
22+
Warning:
23+
Model fit failed; cannot make predictions.
24+
25+
# classification model
26+
27+
Code
28+
cls_res <- predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(
29+
-Class))
30+
Condition
31+
Warning:
32+
Model fit failed; cannot make predictions.
33+
34+
---
35+
36+
Code
37+
prb_res <- predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(
38+
-Class), type = "prob")
39+
Condition
40+
Warning:
41+
Model fit failed; cannot make predictions.
42+
43+
---
44+
45+
Code
46+
ci_res <- predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(
47+
-Class), type = "conf_int")
48+
Condition
49+
Warning:
50+
Model fit failed; cannot make predictions.
51+

tests/testthat/_snaps/linear_reg.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@
137137
Error in `show_engines()`:
138138
! No results found for model function "x".
139139

140+
# lm can handle rankdeficient predictions
141+
142+
Code
143+
preds <- linear_reg() %>% fit(y ~ ., data = data) %>% predict(new_data = data2)
144+
Condition
145+
Warning in `predict.lm()`:
146+
prediction from rank-deficient fit; consider predict(., rankdeficient="NA")
147+
140148
# check_args() works
141149

142150
Code

tests/testthat/_snaps/mlp.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,25 @@
3232
x Engine "wat?" is not supported for `mlp()`
3333
i See `show_engines("mlp")`.
3434

35+
---
36+
37+
Code
38+
translate(mlp(mode = "regression") %>% set_engine("nnet", formula = y ~ x))
39+
Condition
40+
Warning:
41+
The argument `formula` cannot be manually modified and was removed.
42+
Output
43+
Single Layer Neural Network Model Specification (regression)
44+
45+
Main Arguments:
46+
hidden_units = 5
47+
48+
Computational engine: nnet
49+
50+
Model fit template:
51+
nnet::nnet(formula = missing_arg(), data = missing_arg(), size = 5,
52+
trace = FALSE, linout = TRUE)
53+
3554
---
3655

3756
Code

tests/testthat/_snaps/multinom_reg.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@
4040
Error in `set_engine()`:
4141
! Missing engine. Possible mode/engine combinations are: classification {glmnet, spark, keras, nnet, brulee}.
4242

43+
---
44+
45+
Code
46+
translate(multinom_reg(penalty = 0.1) %>% set_engine("glmnet", x = hpc[, 1:3],
47+
y = hpc$class))
48+
Condition
49+
Warning:
50+
The argument `x, y` cannot be manually modified and was removed.
51+
Output
52+
Multinomial Regression Model Specification (classification)
53+
54+
Main Arguments:
55+
penalty = 0.1
56+
57+
Computational engine: glmnet
58+
59+
Model fit template:
60+
glmnet::glmnet(x = missing_arg(), y = missing_arg(), weights = missing_arg(),
61+
family = "multinomial")
62+
4363
# check_args() works
4464

4565
Code

tests/testthat/_snaps/nullmodel.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@
2323
Error in `null_model()`:
2424
! unused argument (formula = y ~ x)
2525

26+
---
27+
28+
Code
29+
translate(null_model(mode = "regression") %>% set_engine("parsnip", x = hpc[, 1:
30+
3], y = hpc$class))
31+
Condition
32+
Warning:
33+
The argument `x, y` cannot be manually modified and was removed.
34+
Output
35+
Null Model Specification (regression)
36+
37+
Computational engine: parsnip
38+
39+
Model fit template:
40+
parsnip::nullmodel(x = missing_arg(), y = missing_arg())
41+
2642
# nullmodel execution
2743

2844
Code

tests/testthat/_snaps/rand_forest_ranger.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@
4646
Warning in `sqrt()`:
4747
NaNs produced
4848

49+
# ranger classification intervals
50+
51+
Code
52+
rgr_se <- predict(extract_fit_engine(lc_fit), data = tail(lending_club), type = "se")$
53+
se
54+
Condition
55+
Warning in `rInfJack()`:
56+
Sample size <=20, no calibration performed.
57+
Warning in `rInfJack()`:
58+
Sample size <=20, no calibration performed.
59+
Warning in `sqrt()`:
60+
NaNs produced
61+
62+
---
63+
64+
Code
65+
parsnip_int <- predict(lc_fit, new_data = tail(lending_club), type = "conf_int",
66+
std_error = TRUE, level = 0.93)
67+
Condition
68+
Warning in `rInfJack()`:
69+
Sample size <=20, no calibration performed.
70+
Warning in `rInfJack()`:
71+
Sample size <=20, no calibration performed.
72+
Warning in `sqrt()`:
73+
NaNs produced
74+
4975
# argument checks for data dimensions
5076

5177
Code

tests/testthat/_snaps/surv_reg.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,17 @@
3636
Error in `if (object$engine == "liquidSVM") ...`:
3737
! argument is of length zero
3838

39+
# deprecation warning
40+
41+
Code
42+
surv_reg()
43+
Condition
44+
Warning:
45+
`surv_reg()` was deprecated in parsnip 0.1.6.
46+
i Please use `survival_reg()` instead.
47+
Output
48+
Parametric Survival Regression Model Specification (regression)
49+
50+
Computational engine: survival
51+
52+

tests/testthat/test-boost_tree_C5.0.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,11 @@ test_that('argument checks for data dimensions', {
140140
set_engine("C5.0") %>%
141141
set_mode("classification")
142142

143-
expect_warning(
144-
f_fit <- spec %>% fit(species ~ ., data = penguins),
145-
"1000 samples were requested"
143+
expect_snapshot(
144+
f_fit <- spec %>% fit(species ~ ., data = penguins)
146145
)
147-
expect_warning(
148-
xy_fit <- spec %>% fit_xy(x = penguins[, -1], y = penguins$species),
149-
"1000 samples were requested"
146+
expect_snapshot(
147+
xy_fit <- spec %>% fit_xy(x = penguins[, -1], y = penguins$species)
150148
)
151149

152150
expect_equal(extract_fit_engine(f_fit)$control$minCases, nrow(penguins))

tests/testthat/test-boost_tree_xgboost.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,11 @@ test_that('early stopping', {
339339
fit(mpg ~ ., data = mtcars[-(1:4), ])
340340
)
341341

342-
expect_warning(
342+
expect_snapshot(
343343
reg_fit <-
344344
boost_tree(trees = 20, stop_iter = 30, mode = "regression") %>%
345345
set_engine("xgboost", validation = .1) %>%
346-
fit(mpg ~ ., data = mtcars[-(1:4), ]),
347-
regex = "`early_stop` was reduced to 19"
346+
fit(mpg ~ ., data = mtcars[-(1:4), ])
348347
)
349348
expect_snapshot(
350349
error = TRUE,
@@ -483,13 +482,11 @@ test_that('argument checks for data dimensions', {
483482
penguins_dummy <- model.matrix(species ~ ., data = penguins)
484483
penguins_dummy <- as.data.frame(penguins_dummy[, -1])
485484

486-
expect_warning(
487-
f_fit <- spec %>% fit(species ~ ., data = penguins, control = ctrl),
488-
"1000 samples were requested"
485+
expect_snapshot(
486+
f_fit <- spec %>% fit(species ~ ., data = penguins, control = ctrl)
489487
)
490-
expect_warning(
491-
xy_fit <- spec %>% fit_xy(x = penguins_dummy, y = penguins$species, control = ctrl),
492-
"1000 samples were requested"
488+
expect_snapshot(
489+
xy_fit <- spec %>% fit_xy(x = penguins_dummy, y = penguins$species, control = ctrl)
493490
)
494491
expect_equal(extract_fit_engine(f_fit)$params$colsample_bynode, 1)
495492
expect_equal(extract_fit_engine(f_fit)$params$min_child_weight, nrow(penguins))

tests/testthat/test-convert_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ test_that("numeric x and numeric multivariate y", {
330330
})
331331

332332
test_that("numeric x and factor y", {
333-
expect_warning(
333+
expect_snapshot(
334334
expected <-
335335
glm(class ~ ., data = hpc, x = TRUE, y = TRUE, family = binomial())
336336
)

tests/testthat/test-failed_models.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ test_that('numeric model', {
2525
set_engine("lm") %>%
2626
fit(compounds ~ ., data = hpc_bad, control = ctrl)
2727

28-
expect_warning(num_res <- predict(lm_mod, hpc_bad[1:11, -1]))
28+
expect_snapshot(num_res <- predict(lm_mod, hpc_bad[1:11, -1]))
2929
expect_equal(num_res, NULL)
3030

31-
expect_warning(ci_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "conf_int"))
31+
expect_snapshot(ci_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "conf_int"))
3232
expect_equal(ci_res, NULL)
3333

34-
expect_warning(pi_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "pred_int"))
34+
expect_snapshot(pi_res <- predict(lm_mod, hpc_bad[1:11, -1], type = "pred_int"))
3535
expect_equal(pi_res, NULL)
3636

3737
})
@@ -44,19 +44,19 @@ test_that('classification model', {
4444
set_engine("glm") %>%
4545
fit(Class ~ log(funded_amnt) + int_rate + big_num, data = lending_club, control = ctrl)
4646

47-
expect_warning(
47+
expect_snapshot(
4848
cls_res <-
4949
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class))
5050
)
5151
expect_equal(cls_res, NULL)
5252

53-
expect_warning(
53+
expect_snapshot(
5454
prb_res <-
5555
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class), type = "prob")
5656
)
5757
expect_equal(prb_res, NULL)
5858

59-
expect_warning(
59+
expect_snapshot(
6060
ci_res <-
6161
predict(log_reg, lending_club %>% dplyr::slice(1:7) %>% dplyr::select(-Class), type = "conf_int")
6262
)

tests/testthat/test-linear_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ test_that('lm can handle rankdeficient predictions', {
327327
x4 = c(0,0,2,3)
328328
)
329329

330-
expect_warning(
330+
expect_snapshot(
331331
preds <- linear_reg() %>%
332332
fit(y ~ ., data = data) %>%
333333
predict(new_data = data2)

tests/testthat/test-mlp.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test_that('updating', {
1111
test_that('bad input', {
1212
expect_snapshot(error = TRUE, mlp(mode = "time series"))
1313
expect_snapshot(error = TRUE, translate(mlp(mode = "classification") %>% set_engine("wat?")))
14-
expect_warning(translate(mlp(mode = "regression") %>% set_engine("nnet", formula = y ~ x)))
14+
expect_snapshot(translate(mlp(mode = "regression") %>% set_engine("nnet", formula = y ~ x)))
1515
expect_snapshot(error = TRUE, translate(mlp(mode = "classification", x = x, y = y) %>% set_engine("keras")))
1616
expect_snapshot(error = TRUE, translate(mlp(mode = "regression", formula = y ~ x) %>% set_engine()))
1717
})

tests/testthat/test-multinom_reg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test_that('bad input', {
1313
expect_snapshot(error = TRUE, multinom_reg(mode = "regression"))
1414
expect_snapshot(error = TRUE, translate(multinom_reg(penalty = 0.1) %>% set_engine("wat?")))
1515
expect_snapshot(error = TRUE, multinom_reg(penalty = 0.1) %>% set_engine())
16-
expect_warning(translate(multinom_reg(penalty = 0.1) %>% set_engine("glmnet", x = hpc[,1:3], y = hpc$class)))
16+
expect_snapshot(translate(multinom_reg(penalty = 0.1) %>% set_engine("glmnet", x = hpc[,1:3], y = hpc$class)))
1717
})
1818

1919
test_that('check_args() works', {

0 commit comments

Comments
 (0)