Skip to content

Commit

Permalink
is_sparse_tibble -> sparsevctrs::has_sparse_elements
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Oct 4, 2024
1 parent 78d7fd2 commit 183f78f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
4 changes: 0 additions & 4 deletions R/sparsevctrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#' @name sparse_data
NULL

is_sparse_tibble <- function(x) {
any(vapply(x, sparsevctrs::is_sparse_vector, logical(1)))
}

is_sparse_matrix <- function(x) {
methods::is(x, "sparseMatrix")
}
28 changes: 14 additions & 14 deletions tests/testthat/test-sparsevctrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ test_that("recipe() accepts sparse tibbles", {
)

expect_true(
is_sparse_tibble(rec_spec$template)
sparsevctrs::has_sparse_elements(rec_spec$template)
)

expect_no_condition(
rec_spec <- recipe(hotel_data)
)

expect_true(
is_sparse_tibble(rec_spec$template)
sparsevctrs::has_sparse_elements(rec_spec$template)
)

expect_no_condition(
rec_spec <- recipe(hotel_data, avg_price_per_room ~ .)
)

expect_true(
is_sparse_tibble(rec_spec$template)
sparsevctrs::has_sparse_elements(rec_spec$template)
)
})

Expand All @@ -42,15 +42,15 @@ test_that("prep() accepts sparse tibbles", {
)

expect_true(
is_sparse_tibble(rec$template)
sparsevctrs::has_sparse_elements(rec$template)
)

expect_no_error(
rec <- prep(rec_spec, training = hotel_data)
)

expect_true(
is_sparse_tibble(rec$template)
sparsevctrs::has_sparse_elements(rec$template)
)
})

Expand All @@ -68,15 +68,15 @@ test_that("bake() accepts sparse tibbles", {
)

expect_true(
is_sparse_tibble(res)
sparsevctrs::has_sparse_elements(res)
)

expect_no_error(
res <- bake(rec_spec, new_data = hotel_data)
)

expect_true(
is_sparse_tibble(res)
sparsevctrs::has_sparse_elements(res)
)
})

Expand All @@ -91,23 +91,23 @@ test_that("recipe() accepts sparse matrices", {
)

expect_true(
is_sparse_tibble(rec_spec$template)
sparsevctrs::has_sparse_elements(rec_spec$template)
)

expect_no_condition(
rec_spec <- recipe(hotel_data)
)

expect_true(
is_sparse_tibble(rec_spec$template)
sparsevctrs::has_sparse_elements(rec_spec$template)
)

expect_no_condition(
rec_spec <- recipe(hotel_data, avg_price_per_room ~ .)
)

expect_true(
is_sparse_tibble(rec_spec$template)
sparsevctrs::has_sparse_elements(rec_spec$template)
)
})

Expand All @@ -124,15 +124,15 @@ test_that("prep() accepts sparse matrices", {
)

expect_true(
is_sparse_tibble(rec$template)
sparsevctrs::has_sparse_elements(rec$template)
)

expect_no_error(
rec <- prep(rec_spec, training = hotel_data)
)

expect_true(
is_sparse_tibble(rec$template)
sparsevctrs::has_sparse_elements(rec$template)
)
})

Expand All @@ -150,15 +150,15 @@ test_that("bake() accepts sparse matrices", {
)

expect_true(
is_sparse_tibble(res)
sparsevctrs::has_sparse_elements(res)
)

expect_no_error(
res <- bake(rec_spec, new_data = hotel_data)
)

expect_true(
is_sparse_tibble(res)
sparsevctrs::has_sparse_elements(res)
)
})

Expand Down

0 comments on commit 183f78f

Please sign in to comment.