@@ -18,29 +18,25 @@ test_that('xgboost execution, classification', {
1818 wts <- ifelse(runif(nrow(hpc )) < .1 , 0 , 1 )
1919 wts <- importance_weights(wts )
2020
21- expect_error ({
21+ expect_no_condition ({
2222 set.seed(1 )
2323 res_f <- parsnip :: fit(
2424 hpc_xgboost ,
2525 class ~ compounds + input_fields ,
2626 data = hpc ,
2727 control = ctrl
2828 )
29- },
30- regexp = NA
31- )
32- expect_error({
29+ })
30+ expect_no_condition({
3331 set.seed(1 )
3432 res_xy <- parsnip :: fit_xy(
3533 hpc_xgboost ,
3634 x = hpc [, c(" compounds" , " input_fields" )],
3735 y = hpc $ class ,
3836 control = ctrl
3937 )
40- },
41- regexp = NA
42- )
43- expect_error({
38+ })
39+ expect_no_condition({
4440 set.seed(1 )
4541 res_f_wts <- parsnip :: fit(
4642 hpc_xgboost ,
@@ -49,10 +45,8 @@ test_that('xgboost execution, classification', {
4945 control = ctrl ,
5046 case_weights = wts
5147 )
52- },
53- regexp = NA
54- )
55- expect_error({
48+ })
49+ expect_no_condition({
5650 set.seed(1 )
5751 res_xy_wts <- parsnip :: fit_xy(
5852 hpc_xgboost ,
@@ -61,9 +55,7 @@ test_that('xgboost execution, classification', {
6155 control = ctrl ,
6256 case_weights = wts
6357 )
64- },
65- regexp = NA
66- )
58+ })
6759
6860 expect_equal(res_f $ fit $ evaluation_log , res_xy $ fit $ evaluation_log )
6961 expect_equal(res_f_wts $ fit $ evaluation_log , res_xy_wts $ fit $ evaluation_log )
@@ -140,24 +132,22 @@ test_that('xgboost execution, regression', {
140132
141133 ctrl $ verbosity <- 0L
142134
143- expect_error (
135+ expect_no_condition (
144136 res <- parsnip :: fit(
145137 car_basic ,
146138 mpg ~ . ,
147139 data = mtcars ,
148140 control = ctrl
149- ),
150- regexp = NA
141+ )
151142 )
152143
153- expect_error (
144+ expect_no_condition (
154145 res <- parsnip :: fit_xy(
155146 car_basic ,
156147 x = mtcars [, num_pred ],
157148 y = mtcars $ mpg ,
158149 control = ctrl
159- ),
160- regexp = NA
150+ )
161151 )
162152
163153 expect_error(
@@ -285,32 +275,29 @@ test_that('validation sets', {
285275
286276 ctrl $ verbosity <- 0L
287277
288- expect_error (
278+ expect_no_condition (
289279 reg_fit <-
290280 boost_tree(trees = 20 , mode = " regression" ) %> %
291281 set_engine(" xgboost" , validation = .1 ) %> %
292- fit(mpg ~ . , data = mtcars [- (1 : 4 ), ]),
293- regex = NA
282+ fit(mpg ~ . , data = mtcars [- (1 : 4 ), ])
294283 )
295284
296285 expect_equal(colnames(extract_fit_engine(reg_fit )$ evaluation_log )[2 ], " validation_rmse" )
297286
298- expect_error (
287+ expect_no_condition (
299288 reg_fit <-
300289 boost_tree(trees = 20 , mode = " regression" ) %> %
301290 set_engine(" xgboost" , validation = .1 , eval_metric = " mae" ) %> %
302- fit(mpg ~ . , data = mtcars [- (1 : 4 ), ]),
303- regex = NA
291+ fit(mpg ~ . , data = mtcars [- (1 : 4 ), ])
304292 )
305293
306294 expect_equal(colnames(extract_fit_engine(reg_fit )$ evaluation_log )[2 ], " validation_mae" )
307295
308- expect_error (
296+ expect_no_condition (
309297 reg_fit <-
310298 boost_tree(trees = 20 , mode = " regression" ) %> %
311299 set_engine(" xgboost" , eval_metric = " mae" ) %> %
312- fit(mpg ~ . , data = mtcars [- (1 : 4 ), ]),
313- regex = NA
300+ fit(mpg ~ . , data = mtcars [- (1 : 4 ), ])
314301 )
315302
316303 expect_equal(colnames(extract_fit_engine(reg_fit )$ evaluation_log )[2 ], " training_mae" )
@@ -334,23 +321,21 @@ test_that('early stopping', {
334321 ctrl $ verbosity <- 0L
335322
336323 set.seed(233456 )
337- expect_error (
324+ expect_no_condition (
338325 reg_fit <-
339326 boost_tree(trees = 200 , stop_iter = 5 , mode = " regression" ) %> %
340327 set_engine(" xgboost" , validation = .1 ) %> %
341- fit(mpg ~ . , data = mtcars [- (1 : 4 ), ]),
342- regex = NA
328+ fit(mpg ~ . , data = mtcars [- (1 : 4 ), ])
343329 )
344330
345331 expect_equal(extract_fit_engine(reg_fit )$ niter - extract_fit_engine(reg_fit )$ best_iteration , 5 )
346332 expect_true(extract_fit_engine(reg_fit )$ niter < 200 )
347333
348- expect_error (
334+ expect_no_condition (
349335 reg_fit <-
350336 boost_tree(trees = 20 , mode = " regression" ) %> %
351337 set_engine(" xgboost" , validation = .1 , eval_metric = " mae" ) %> %
352- fit(mpg ~ . , data = mtcars [- (1 : 4 ), ]),
353- regex = NA
338+ fit(mpg ~ . , data = mtcars [- (1 : 4 ), ])
354339 )
355340
356341 expect_warning(
@@ -380,39 +365,39 @@ test_that('xgboost data conversion', {
380365 mtcar_smat <- Matrix :: Matrix(mtcar_mat , sparse = TRUE )
381366 wts <- 1 : 32
382367
383- expect_error (from_df <- parsnip ::: as_xgb_data(mtcar_x , mtcars $ mpg ), regexp = NA )
368+ expect_no_condition (from_df <- parsnip ::: as_xgb_data(mtcar_x , mtcars $ mpg ))
384369 expect_true(inherits(from_df $ data , " xgb.DMatrix" ))
385370 expect_true(inherits(from_df $ watchlist $ training , " xgb.DMatrix" ))
386371
387- expect_error (from_mat <- parsnip ::: as_xgb_data(mtcar_mat , mtcars $ mpg ), regexp = NA )
372+ expect_no_condition (from_mat <- parsnip ::: as_xgb_data(mtcar_mat , mtcars $ mpg ))
388373 expect_true(inherits(from_mat $ data , " xgb.DMatrix" ))
389374 expect_true(inherits(from_mat $ watchlist $ training , " xgb.DMatrix" ))
390375
391- expect_error (from_sparse <- parsnip ::: as_xgb_data(mtcar_smat , mtcars $ mpg ), regexp = NA )
376+ expect_no_condition (from_sparse <- parsnip ::: as_xgb_data(mtcar_smat , mtcars $ mpg ))
392377 expect_true(inherits(from_mat $ data , " xgb.DMatrix" ))
393378 expect_true(inherits(from_mat $ watchlist $ training , " xgb.DMatrix" ))
394379
395- expect_error (from_df <- parsnip ::: as_xgb_data(mtcar_x , mtcars $ mpg , validation = .1 ), regexp = NA )
380+ expect_no_condition (from_df <- parsnip ::: as_xgb_data(mtcar_x , mtcars $ mpg , validation = .1 ))
396381 expect_true(inherits(from_df $ data , " xgb.DMatrix" ))
397382 expect_true(inherits(from_df $ watchlist $ validation , " xgb.DMatrix" ))
398383 expect_true(nrow(from_df $ data ) > nrow(from_df $ watchlist $ validation ))
399384
400- expect_error (from_mat <- parsnip ::: as_xgb_data(mtcar_mat , mtcars $ mpg , validation = .1 ), regexp = NA )
385+ expect_no_condition (from_mat <- parsnip ::: as_xgb_data(mtcar_mat , mtcars $ mpg , validation = .1 ))
401386 expect_true(inherits(from_mat $ data , " xgb.DMatrix" ))
402387 expect_true(inherits(from_mat $ watchlist $ validation , " xgb.DMatrix" ))
403388 expect_true(nrow(from_mat $ data ) > nrow(from_mat $ watchlist $ validation ))
404389
405- expect_error (from_sparse <- parsnip ::: as_xgb_data(mtcar_smat , mtcars $ mpg , validation = .1 ), regexp = NA )
390+ expect_no_condition (from_sparse <- parsnip ::: as_xgb_data(mtcar_smat , mtcars $ mpg , validation = .1 ))
406391 expect_true(inherits(from_mat $ data , " xgb.DMatrix" ))
407392 expect_true(inherits(from_mat $ watchlist $ validation , " xgb.DMatrix" ))
408393 expect_true(nrow(from_sparse $ data ) > nrow(from_sparse $ watchlist $ validation ))
409394
410395 # set event_level for factors
411396
412397 mtcars_y <- factor (mtcars $ mpg < 15 , levels = c(TRUE , FALSE ), labels = c(" low" , " high" ))
413- expect_error (from_df <- parsnip ::: as_xgb_data(mtcar_x , mtcars_y ), regexp = NA )
398+ expect_no_condition (from_df <- parsnip ::: as_xgb_data(mtcar_x , mtcars_y ))
414399 expect_equal(xgboost :: getinfo(from_df $ data , name = " label" )[1 : 5 ], rep(0 , 5 ))
415- expect_error (from_df <- parsnip ::: as_xgb_data(mtcar_x , mtcars_y , event_level = " second" ), regexp = NA )
400+ expect_no_condition (from_df <- parsnip ::: as_xgb_data(mtcar_x , mtcars_y , event_level = " second" ))
416401 expect_equal(xgboost :: getinfo(from_df $ data , name = " label" )[1 : 5 ], rep(1 , 5 ))
417402
418403 mtcars_y <- factor (mtcars $ mpg < 15 , levels = c(TRUE , FALSE , " na" ), labels = c(" low" , " high" , " missing" ))
@@ -421,9 +406,13 @@ test_that('xgboost data conversion', {
421406 )
422407
423408 # case weights added
424- expect_error(wted <- parsnip ::: as_xgb_data(mtcar_x , mtcars $ mpg , weights = wts ), regexp = NA )
409+ expect_no_condition(
410+ wted <- parsnip ::: as_xgb_data(mtcar_x , mtcars $ mpg , weights = wts )
411+ )
425412 expect_equal(wts , xgboost :: getinfo(wted $ data , " weight" ))
426- expect_error(wted_val <- parsnip ::: as_xgb_data(mtcar_x , mtcars $ mpg , weights = wts , validation = 1 / 4 ), regexp = NA )
413+ expect_no_condition(
414+ wted_val <- parsnip ::: as_xgb_data(mtcar_x , mtcars $ mpg , weights = wts , validation = 1 / 4 )
415+ )
427416 expect_true(all(xgboost :: getinfo(wted_val $ data , " weight" ) %in% wts ))
428417 expect_null(xgboost :: getinfo(wted_val $ watchlist $ validation , " weight" ))
429418
@@ -461,9 +450,13 @@ test_that('xgboost data and sparse matrices', {
461450 expect_equal(extract_fit_engine(from_df ), extract_fit_engine(from_sparse ), ignore_function_env = TRUE )
462451
463452 # case weights added
464- expect_error(wted <- parsnip ::: as_xgb_data(mtcar_smat , mtcars $ mpg , weights = wts ), regexp = NA )
453+ expect_no_condition(
454+ wted <- parsnip ::: as_xgb_data(mtcar_smat , mtcars $ mpg , weights = wts )
455+ )
465456 expect_equal(wts , xgboost :: getinfo(wted $ data , " weight" ))
466- expect_error(wted_val <- parsnip ::: as_xgb_data(mtcar_smat , mtcars $ mpg , weights = wts , validation = 1 / 4 ), regexp = NA )
457+ expect_no_condition(
458+ wted_val <- parsnip ::: as_xgb_data(mtcar_smat , mtcars $ mpg , weights = wts , validation = 1 / 4 )
459+ )
467460 expect_true(all(xgboost :: getinfo(wted_val $ data , " weight" ) %in% wts ))
468461 expect_null(xgboost :: getinfo(wted_val $ watchlist $ validation , " weight" ))
469462
0 commit comments