Skip to content

Commit bb361a2

Browse files
committed
test that call is passed to coerce_ functions
1 parent ee072ce commit bb361a2

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Imports:
3232
prettyunits,
3333
purrr (>= 1.0.0),
3434
rlang (>= 1.1.0),
35-
sparsevctrs (>= 0.1.0.9000),
35+
sparsevctrs (>= 0.1.0.9002),
3636
stats,
3737
tibble (>= 2.1.1),
3838
tidyr (>= 1.3.0),

R/fit.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fit.model_spec <-
136136

137137

138138
if (is_sparse_matrix(data)) {
139-
data <- sparsevctrs::coerce_to_sparse_tibble(data)
139+
data <- sparsevctrs::coerce_to_sparse_tibble(data, rlang::caller_env(0))
140140
}
141141

142142
dots <- quos(...)

tests/testthat/_snaps/sparsevctrs.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
Warning:
3131
`data` is a sparse tibble, but `linear_reg()` with engine "lm" doesn't accept that. Converting to non-sparse.
3232

33+
---
34+
35+
Code
36+
fit(spec, avg_price_per_room ~ ., data = hotel_data)
37+
Condition
38+
Error in `fit()`:
39+
! `x` must have column names.
40+
3341
# sparse tibble can be passed to `fit_xy() - unsupported
3442

3543
Code

tests/testthat/test-sparsevctrs.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,17 @@ test_that("maybe_sparse_matrix() is used correctly", {
313313
fit_xy(spec, x = tibble::as_tibble(mtcars)[, -1], y = tibble::as_tibble(mtcars)[, 1])
314314
)
315315
})
316+
317+
test_that("fit() errors if sparse matrix has no colnames", {
318+
hotel_data <- sparse_hotel_rates()
319+
colnames(hotel_data) <- NULL
320+
321+
spec <- boost_tree() %>%
322+
set_mode("regression") %>%
323+
set_engine("xgboost")
324+
325+
expect_snapshot(
326+
error = TRUE,
327+
fit(spec, avg_price_per_room ~ ., data = hotel_data)
328+
)
329+
})

0 commit comments

Comments
 (0)