Skip to content

Commit b180de8

Browse files
transition to snapshot testing (#1190)
--------- Co-authored-by: Emil Hvitfeldt <[email protected]>
1 parent 6109bc1 commit b180de8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1671
-213
lines changed

tests/testthat/_snaps/adds.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# adding row indicies
2+
3+
Code
4+
as.matrix(mtcars) %>% add_rowindex()
5+
Condition
6+
Error in `add_rowindex()`:
7+
! `x` should be a data frame.
8+

tests/testthat/_snaps/args_and_modes.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
# pipe arguments
2+
3+
Code
4+
rand_forest() %>% set_args()
5+
Condition
6+
Error in `set_args()`:
7+
! Please pass at least one named argument.
8+
9+
# pipe engine
10+
11+
Code
12+
rand_forest() %>% set_mode()
13+
Condition
14+
Error in `set_mode()`:
15+
! Available modes for model type rand_forest are: "unknown", "classification", "regression", and "censored regression".
16+
17+
---
18+
19+
Code
20+
rand_forest() %>% set_mode(2)
21+
Condition
22+
Error in `set_mode()`:
23+
! 2 is not a known mode for model `rand_forest()`.
24+
25+
---
26+
27+
Code
28+
rand_forest() %>% set_mode("haberdashery")
29+
Condition
30+
Error in `set_mode()`:
31+
! "haberdashery" is not a known mode for model `rand_forest()`.
32+
133
# can't set a mode that isn't allowed by the model spec
234

335
Code

tests/testthat/_snaps/boost_tree.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@
2323
Error in `boost_tree()`:
2424
! "bogus" is not a known mode for model `boost_tree()`.
2525

26+
---
27+
28+
Code
29+
translate(boost_tree(mode = "classification"), engine = NULL)
30+
Message
31+
Used `engine = 'xgboost'` for translation.
32+
Output
33+
Boosted Tree Model Specification (classification)
34+
35+
Computational engine: xgboost
36+
37+
Model fit template:
38+
parsnip::xgb_train(x = missing_arg(), y = missing_arg(), weights = missing_arg(),
39+
nthread = 1, verbose = 0)
40+
41+
---
42+
43+
Code
44+
translate(boost_tree(formula = y ~ x))
45+
Condition
46+
Error in `boost_tree()`:
47+
! unused argument (formula = y ~ x)
48+
2649
# check_args() works
2750

2851
Code

tests/testthat/_snaps/boost_tree_C5.0.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# C5.0 execution
2+
3+
Code
4+
res <- fit(lc_basic, funded_amnt ~ term, data = lending_club, engine = "C5.0",
5+
control = ctrl)
6+
Condition
7+
Error in `glue()`:
8+
! Expecting '}'
9+
110
# submodel prediction
211

312
Code
@@ -6,3 +15,21 @@
615
Error in `multi_predict()`:
716
! Please use `new_data` instead of `newdata`.
817

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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
# xgboost execution, classification
2+
3+
Code
4+
res <- parsnip::fit(hpc_xgboost, class ~ novar, data = hpc, control = ctrl)
5+
Condition
6+
Error:
7+
! object 'novar' not found
8+
9+
# xgboost execution, regression
10+
11+
Code
12+
res <- parsnip::fit_xy(car_basic, x = mtcars[, num_pred], y = factor(mtcars$vs),
13+
control = ctrl)
14+
Condition
15+
Error in `check_outcome()`:
16+
! For a regression model, the outcome should be `numeric`, not a `factor`.
17+
118
# submodel prediction
219

320
Code
@@ -6,6 +23,35 @@
623
Error in `multi_predict()`:
724
! Please use `new_data` instead of `newdata`.
825

26+
# validation sets
27+
28+
Code
29+
reg_fit <- boost_tree(trees = 20, mode = "regression") %>% set_engine("xgboost",
30+
validation = 3) %>% fit(mpg ~ ., data = mtcars[-(1:4), ])
31+
Condition
32+
Error in `parsnip::xgb_train()`:
33+
! `validation` should be on [0, 1).
34+
35+
# early stopping
36+
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+
47+
Code
48+
reg_fit <- boost_tree(trees = 20, stop_iter = 0, mode = "regression") %>%
49+
set_engine("xgboost", validation = 0.1) %>% fit(mpg ~ ., data = mtcars[-(1:4),
50+
])
51+
Condition
52+
Error in `parsnip::xgb_train()`:
53+
! `early_stop` should be on [2, 20).
54+
955
# xgboost data conversion
1056

1157
Code
@@ -14,6 +60,34 @@
1460
Warning:
1561
`event_level` can only be set for binary outcomes.
1662

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+
81+
# count/proportion parameters
82+
83+
Code
84+
boost_tree(mtry = 0.9, trees = 4) %>% set_engine("xgboost") %>% set_mode(
85+
"regression") %>% fit(mpg ~ ., data = mtcars)
86+
Condition
87+
Error in `recalc_param()`:
88+
! The option `counts = TRUE` was used but `colsample_bynode` was given as 0.9.
89+
i Please use a value >= 1 or use `counts = FALSE`.
90+
1791
# interface to param arguments
1892

1993
! Please supply elements of the `params` list argument as main arguments to `set_engine()` rather than as part of `params`.

tests/testthat/_snaps/convert_data.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1+
# numeric y and mixed x, fail missing data
2+
3+
Code
4+
.convert_form_to_xy_fit(rate ~ ., data = Puromycin_miss, na.action = na.fail,
5+
indicators = "traditional", remove_intercept = TRUE)
6+
Condition
7+
Error in `na.fail.default()`:
8+
! missing values in object
9+
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+
18+
# bad args
19+
20+
Code
21+
.convert_form_to_xy_fit(mpg ~ ., data = mtcars, composition = "tibble",
22+
indicators = "traditional", remove_intercept = TRUE)
23+
Condition
24+
Error in `.convert_form_to_xy_fit()`:
25+
! `composition` should be either "data.frame", "matrix", or "dgCMatrix".
26+
27+
---
28+
29+
Code
30+
.convert_form_to_xy_fit(mpg ~ ., data = mtcars, weights = letters[1:nrow(mtcars)],
31+
indicators = "traditional", remove_intercept = TRUE)
32+
Condition
33+
Error in `.convert_form_to_xy_fit()`:
34+
! `weights` must be a numeric vector.
35+
36+
---
37+
38+
Code
39+
.convert_xy_to_form_fit(mtcars$disp, mtcars$mpg, remove_intercept = TRUE)
40+
Condition
41+
Error in `.convert_xy_to_form_fit()`:
42+
! `x` cannot be a vector.
43+
44+
---
45+
46+
Code
47+
.convert_xy_to_form_fit(mtcars[, 1:3], mtcars[, 2:5], remove_intercept = TRUE)
48+
Condition
49+
Error in `.convert_xy_to_form_fit()`:
50+
! `x` and `y` have the names "cyl" and "disp" in common.
51+
i Please ensure that `x` and `y` don't share any column names.
52+
153
# convert to matrix
254

355
Code

tests/testthat/_snaps/descriptors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# can be temporarily overriden at evaluation time
2+
3+
Code
4+
.cols()
5+
Condition
6+
Error in `descr_env$.cols()`:
7+
! Descriptor context not set
8+

tests/testthat/_snaps/extract.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
i The parsnip extension package baguette implements support for this specification.
3939
i Please install (if needed) and load to continue.
4040

41+
# extract single parameter from model with no parameters
42+
43+
Code
44+
extract_parameter_dials(lm_model, parameter = "none there")
45+
Condition
46+
Error in `extract_parameter_dials()`:
47+
! No parameter exists with id "none there".
48+
4149
# extract_fit_time() works
4250

4351
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/fit_interfaces.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
# wrong args
2+
3+
Code
4+
tester_xy(NULL, x = sprk, y = hpc, model = rmod)
5+
Condition
6+
Error in `tester_xy()`:
7+
! `x` should be a <data.frame/matrix>, not an <integer> object.
8+
9+
---
10+
11+
Code
12+
tester(NULL, f, data = as.matrix(hpc[, 1:4]))
13+
Condition
14+
Error in `tester()`:
15+
! `data` should be a <data.frame/dgCMatrix/tbl_spark>, not a double matrix.
16+
17+
# unknown modes
18+
19+
Code
20+
fit(mars_spec, am ~ ., data = mtcars)
21+
Condition
22+
Error in `fit()`:
23+
! Please set the mode in the model specification.
24+
25+
---
26+
27+
Code
28+
fit_xy(mars_spec, x = mtcars[, -1], y = mtcars[, 1])
29+
Condition
30+
Error in `fit_xy()`:
31+
! Please set the mode in the model specification.
32+
33+
---
34+
35+
Code
36+
fit_xy(mars_spec, x = lending_club[, 1:2], y = lending_club$Class)
37+
Condition
38+
Error in `fit_xy()`:
39+
! Please set the mode in the model specification.
40+
141
# misspecified formula argument
242

343
Code
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# regression
2+
3+
Code
4+
xy_res <- fit_xy(reg_mod, x = mtcars[, 1:5], y = mtcars$mpg, control = ctrl)
5+
Condition
6+
Error in `fit_xy()`:
7+
! Please use `fit()` rather than `fit_xy()` to train generalized additive models with the "mgcv" engine.
8+
i See `?model_formula()` to learn more.
9+
10+
# classification
11+
12+
Code
13+
xy_res <- fit_xy(cls_mod, x = two_class_dat[, 2:3], y = two_class_dat$Class,
14+
control = ctrl)
15+
Condition
16+
Error in `fit_xy()`:
17+
! Please use `fit()` rather than `fit_xy()` to train generalized additive models with the "mgcv" engine.
18+
i See `?model_formula()` to learn more.
19+

0 commit comments

Comments
 (0)