@@ -18,29 +18,25 @@ test_that('xgboost execution, classification', {
18
18
wts <- ifelse(runif(nrow(hpc )) < .1 , 0 , 1 )
19
19
wts <- importance_weights(wts )
20
20
21
- expect_error ({
21
+ expect_no_condition ({
22
22
set.seed(1 )
23
23
res_f <- parsnip :: fit(
24
24
hpc_xgboost ,
25
25
class ~ compounds + input_fields ,
26
26
data = hpc ,
27
27
control = ctrl
28
28
)
29
- },
30
- regexp = NA
31
- )
32
- expect_error({
29
+ })
30
+ expect_no_condition({
33
31
set.seed(1 )
34
32
res_xy <- parsnip :: fit_xy(
35
33
hpc_xgboost ,
36
34
x = hpc [, c(" compounds" , " input_fields" )],
37
35
y = hpc $ class ,
38
36
control = ctrl
39
37
)
40
- },
41
- regexp = NA
42
- )
43
- expect_error({
38
+ })
39
+ expect_no_condition({
44
40
set.seed(1 )
45
41
res_f_wts <- parsnip :: fit(
46
42
hpc_xgboost ,
@@ -49,10 +45,8 @@ test_that('xgboost execution, classification', {
49
45
control = ctrl ,
50
46
case_weights = wts
51
47
)
52
- },
53
- regexp = NA
54
- )
55
- expect_error({
48
+ })
49
+ expect_no_condition({
56
50
set.seed(1 )
57
51
res_xy_wts <- parsnip :: fit_xy(
58
52
hpc_xgboost ,
@@ -61,9 +55,7 @@ test_that('xgboost execution, classification', {
61
55
control = ctrl ,
62
56
case_weights = wts
63
57
)
64
- },
65
- regexp = NA
66
- )
58
+ })
67
59
68
60
expect_equal(res_f $ fit $ evaluation_log , res_xy $ fit $ evaluation_log )
69
61
expect_equal(res_f_wts $ fit $ evaluation_log , res_xy_wts $ fit $ evaluation_log )
@@ -140,24 +132,22 @@ test_that('xgboost execution, regression', {
140
132
141
133
ctrl $ verbosity <- 0L
142
134
143
- expect_error (
135
+ expect_no_condition (
144
136
res <- parsnip :: fit(
145
137
car_basic ,
146
138
mpg ~ . ,
147
139
data = mtcars ,
148
140
control = ctrl
149
- ),
150
- regexp = NA
141
+ )
151
142
)
152
143
153
- expect_error (
144
+ expect_no_condition (
154
145
res <- parsnip :: fit_xy(
155
146
car_basic ,
156
147
x = mtcars [, num_pred ],
157
148
y = mtcars $ mpg ,
158
149
control = ctrl
159
- ),
160
- regexp = NA
150
+ )
161
151
)
162
152
163
153
expect_error(
@@ -285,32 +275,29 @@ test_that('validation sets', {
285
275
286
276
ctrl $ verbosity <- 0L
287
277
288
- expect_error (
278
+ expect_no_condition (
289
279
reg_fit <-
290
280
boost_tree(trees = 20 , mode = " regression" ) %> %
291
281
set_engine(" xgboost" , validation = .1 ) %> %
292
- fit(mpg ~ . , data = mtcars [- (1 : 4 ), ]),
293
- regex = NA
282
+ fit(mpg ~ . , data = mtcars [- (1 : 4 ), ])
294
283
)
295
284
296
285
expect_equal(colnames(extract_fit_engine(reg_fit )$ evaluation_log )[2 ], " validation_rmse" )
297
286
298
- expect_error (
287
+ expect_no_condition (
299
288
reg_fit <-
300
289
boost_tree(trees = 20 , mode = " regression" ) %> %
301
290
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 ), ])
304
292
)
305
293
306
294
expect_equal(colnames(extract_fit_engine(reg_fit )$ evaluation_log )[2 ], " validation_mae" )
307
295
308
- expect_error (
296
+ expect_no_condition (
309
297
reg_fit <-
310
298
boost_tree(trees = 20 , mode = " regression" ) %> %
311
299
set_engine(" xgboost" , eval_metric = " mae" ) %> %
312
- fit(mpg ~ . , data = mtcars [- (1 : 4 ), ]),
313
- regex = NA
300
+ fit(mpg ~ . , data = mtcars [- (1 : 4 ), ])
314
301
)
315
302
316
303
expect_equal(colnames(extract_fit_engine(reg_fit )$ evaluation_log )[2 ], " training_mae" )
@@ -334,23 +321,21 @@ test_that('early stopping', {
334
321
ctrl $ verbosity <- 0L
335
322
336
323
set.seed(233456 )
337
- expect_error (
324
+ expect_no_condition (
338
325
reg_fit <-
339
326
boost_tree(trees = 200 , stop_iter = 5 , mode = " regression" ) %> %
340
327
set_engine(" xgboost" , validation = .1 ) %> %
341
- fit(mpg ~ . , data = mtcars [- (1 : 4 ), ]),
342
- regex = NA
328
+ fit(mpg ~ . , data = mtcars [- (1 : 4 ), ])
343
329
)
344
330
345
331
expect_equal(extract_fit_engine(reg_fit )$ niter - extract_fit_engine(reg_fit )$ best_iteration , 5 )
346
332
expect_true(extract_fit_engine(reg_fit )$ niter < 200 )
347
333
348
- expect_error (
334
+ expect_no_condition (
349
335
reg_fit <-
350
336
boost_tree(trees = 20 , mode = " regression" ) %> %
351
337
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 ), ])
354
339
)
355
340
356
341
expect_warning(
@@ -380,39 +365,39 @@ test_that('xgboost data conversion', {
380
365
mtcar_smat <- Matrix :: Matrix(mtcar_mat , sparse = TRUE )
381
366
wts <- 1 : 32
382
367
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 ))
384
369
expect_true(inherits(from_df $ data , " xgb.DMatrix" ))
385
370
expect_true(inherits(from_df $ watchlist $ training , " xgb.DMatrix" ))
386
371
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 ))
388
373
expect_true(inherits(from_mat $ data , " xgb.DMatrix" ))
389
374
expect_true(inherits(from_mat $ watchlist $ training , " xgb.DMatrix" ))
390
375
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 ))
392
377
expect_true(inherits(from_mat $ data , " xgb.DMatrix" ))
393
378
expect_true(inherits(from_mat $ watchlist $ training , " xgb.DMatrix" ))
394
379
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 ))
396
381
expect_true(inherits(from_df $ data , " xgb.DMatrix" ))
397
382
expect_true(inherits(from_df $ watchlist $ validation , " xgb.DMatrix" ))
398
383
expect_true(nrow(from_df $ data ) > nrow(from_df $ watchlist $ validation ))
399
384
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 ))
401
386
expect_true(inherits(from_mat $ data , " xgb.DMatrix" ))
402
387
expect_true(inherits(from_mat $ watchlist $ validation , " xgb.DMatrix" ))
403
388
expect_true(nrow(from_mat $ data ) > nrow(from_mat $ watchlist $ validation ))
404
389
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 ))
406
391
expect_true(inherits(from_mat $ data , " xgb.DMatrix" ))
407
392
expect_true(inherits(from_mat $ watchlist $ validation , " xgb.DMatrix" ))
408
393
expect_true(nrow(from_sparse $ data ) > nrow(from_sparse $ watchlist $ validation ))
409
394
410
395
# set event_level for factors
411
396
412
397
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 ))
414
399
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" ))
416
401
expect_equal(xgboost :: getinfo(from_df $ data , name = " label" )[1 : 5 ], rep(1 , 5 ))
417
402
418
403
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', {
421
406
)
422
407
423
408
# 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
+ )
425
412
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
+ )
427
416
expect_true(all(xgboost :: getinfo(wted_val $ data , " weight" ) %in% wts ))
428
417
expect_null(xgboost :: getinfo(wted_val $ watchlist $ validation , " weight" ))
429
418
@@ -461,9 +450,13 @@ test_that('xgboost data and sparse matrices', {
461
450
expect_equal(extract_fit_engine(from_df ), extract_fit_engine(from_sparse ), ignore_function_env = TRUE )
462
451
463
452
# 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
+ )
465
456
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
+ )
467
460
expect_true(all(xgboost :: getinfo(wted_val $ data , " weight" ) %in% wts ))
468
461
expect_null(xgboost :: getinfo(wted_val $ watchlist $ validation , " weight" ))
469
462
0 commit comments