Skip to content

Commit f2faed9

Browse files
committed
convert warning to error
1 parent 7718d67 commit f2faed9

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

R/sparsevctrs.R

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ to_sparse_data_frame <- function(x, object) {
33
if (allow_sparse(object)) {
44
x <- sparsevctrs::coerce_to_sparse_data_frame(x)
55
} else {
6-
cli::cli_warn(c(
7-
"!" = "{.arg x} is a sparse matrix, but model doesn't accept that.",
8-
"i" = "Converted {.arg x} to data.frame."
9-
))
10-
x <- as.data.frame(as.matrix(x))
6+
cli::cli_abort(
7+
"{.arg x} is a sparse matrix, but {.fn {class(object)[1]}} with
8+
engine {.code {object$engine}} doesn't accept that.")
119
}
1210
}
1311
x
14-
}
12+
}

tests/testthat/_snaps/sparsevctrs.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
Code
44
lm_fit <- fit_xy(spec, x = hotel_data[1:100, -1], y = hotel_data[1:100, 1])
55
Condition
6-
Warning:
7-
! `x` is a sparse matrix, but model doesn't accept that.
8-
i Converted `x` to data.frame.
6+
Error in `to_sparse_data_frame()`:
7+
! `x` is a sparse matrix, but `linear_reg()` with engine `lm` doesn't accept that.
98

109
# to_sparse_data_frame() is used correctly
1110

tests/testthat/test-sparsevctrs.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ test_that("sparse matrices can be passed to `fit_xy()", {
1616
set_engine("lm")
1717

1818
expect_snapshot(
19-
lm_fit <- fit_xy(spec, x = hotel_data[1:100, -1], y = hotel_data[1:100, 1])
19+
lm_fit <- fit_xy(spec, x = hotel_data[1:100, -1], y = hotel_data[1:100, 1]),
20+
error = TRUE
2021
)
2122
})
2223

2324
test_that("to_sparse_data_frame() is used correctly", {
2425
skip_if_not_installed("LiblineaR")
25-
26+
2627
local_mocked_bindings(
2728
to_sparse_data_frame = function(x, object) {
2829
if (methods::is(x, "sparseMatrix")) {
@@ -49,7 +50,7 @@ test_that("to_sparse_data_frame() is used correctly", {
4950
error = TRUE,
5051
fit_xy(spec, x = hotel_data[, -1], y = hotel_data[, 1])
5152
)
52-
53+
5354
spec <- svm_linear() %>%
5455
set_mode("regression") %>%
5556
set_engine("LiblineaR")
@@ -62,7 +63,7 @@ test_that("to_sparse_data_frame() is used correctly", {
6263

6364
test_that("maybe_sparse_matrix() is used correctly", {
6465
skip_if_not_installed("LiblineaR")
65-
66+
6667
local_mocked_bindings(
6768
maybe_sparse_matrix = function(x) {
6869
if (any(vapply(x, sparsevctrs::is_sparse_vector, logical(1)))) {

0 commit comments

Comments
 (0)