Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/testthat/test-adjust_equivocal_zone.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ test_that("arrow - adjust_equivocal_zone works", {
mtcars_tbl <- arrow::as_arrow_table(mtcars_eq)

expect_identical(
dplyr::pull(predict(orb_fit, mtcars_tbl), .pred_class, as_vector = TRUE),
dplyr::collect(predict(orb_fit, mtcars_tbl))$.pred_class,
exp
)
})
44 changes: 30 additions & 14 deletions tests/testthat/test-step_impute_mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ test_that("step_impute_mode works", {
mtcars$carb <- letters[mtcars$carb]
mtcars[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_impute_mode(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec)))

Expand All @@ -26,10 +26,10 @@ test_that("step_impute_mode only calculates what is sufficient", {
mtcars$carb <- letters[mtcars$carb]
mtcars[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_impute_mode(recipes::all_nominal_predictors()) |>
recipes::step_rm(gear) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

expect_identical(
names(orbital(rec)),
Expand All @@ -45,9 +45,9 @@ test_that("step_impute_mode works with empty selections", {
mtcars$carb <- letters[mtcars$carb]
mtcars[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_impute_mode() |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec)))

Expand All @@ -67,9 +67,13 @@ test_that("spark - step_impute_mode works", {
mtcars_impute_mode$carb <- letters[mtcars$carb]
mtcars_impute_mode[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_mode) |>
rec <- recipes::recipe(
mpg ~ .,
data = mtcars_impute_mode,
strings_as_factors = FALSE
) |>
recipes::step_impute_mode(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars_impute_mode, !!!orbital_inline(orbital(rec)))

Expand All @@ -93,9 +97,13 @@ test_that("SQLite - step_impute_mode works", {
mtcars_impute_mode$carb <- letters[mtcars$carb]
mtcars_impute_mode[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_mode) |>
rec <- recipes::recipe(
mpg ~ .,
data = mtcars_impute_mode,
strings_as_factors = FALSE
) |>
recipes::step_impute_mode(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars_impute_mode, !!!orbital_inline(orbital(rec)))

Expand All @@ -120,9 +128,13 @@ test_that("duckdb - step_impute_mode works", {
mtcars_impute_mode$carb <- letters[mtcars$carb]
mtcars_impute_mode[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_mode) |>
rec <- recipes::recipe(
mpg ~ .,
data = mtcars_impute_mode,
strings_as_factors = FALSE
) |>
recipes::step_impute_mode(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars_impute_mode, !!!orbital_inline(orbital(rec)))

Expand All @@ -146,9 +158,13 @@ test_that("arrow - step_impute_mode works", {
mtcars_impute_mode$carb <- letters[mtcars$carb]
mtcars_impute_mode[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_mode) |>
rec <- recipes::recipe(
mpg ~ .,
data = mtcars_impute_mode,
strings_as_factors = FALSE
) |>
recipes::step_impute_mode(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars_impute_mode, !!!orbital_inline(orbital(rec)))

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-step_novel.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ test_that("step_novel works", {
mtcars$gear <- letters[mtcars$gear]
mtcars$carb <- letters[mtcars$carb]

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_novel(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

mtcars[1, 10] <- "aaaaa"

Expand All @@ -30,10 +30,10 @@ test_that("step_novel only calculates what is sufficient", {
mtcars$gear <- letters[mtcars$gear]
mtcars$carb <- letters[mtcars$carb]

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_novel(recipes::all_nominal_predictors()) |>
recipes::step_rm(gear) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

expect_identical(
names(orbital(rec)),
Expand All @@ -49,9 +49,9 @@ test_that("step_novel works with empty selections", {
mtcars$gear <- letters[mtcars$gear]
mtcars$carb <- letters[mtcars$carb]

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_novel() |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

mtcars[1, 10] <- "aaaaa"

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-step_other.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ test_that("step_other works", {
mtcars$gear[1] <- "aa"
mtcars$carb[1] <- "aa"

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_other(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec)))

Expand All @@ -32,10 +32,10 @@ test_that("step_other only calculates what is sufficient", {
mtcars$gear[1] <- "aa"
mtcars$carb[1] <- "aa"

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_other(recipes::all_nominal_predictors()) |>
recipes::step_rm(gear) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

expect_identical(
names(orbital(rec)),
Expand All @@ -53,9 +53,9 @@ test_that("step_other works with empty selections", {
mtcars$gear[1] <- "aa"
mtcars$carb[1] <- "aa"

rec <- recipes::recipe(mpg ~ ., data = mtcars) |>
rec <- recipes::recipe(mpg ~ ., data = mtcars, strings_as_factors = FALSE) |>
recipes::step_other() |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars, !!!orbital_inline(orbital(rec)))

Expand Down
20 changes: 2 additions & 18 deletions tests/testthat/test-step_select.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
test_that("step_select works", {
skip_if_not_installed("recipes")

mtcars0 <- mtcars
mtcars0$zv <- 0

rec_exp <- recipes::recipe(mpg ~ ., data = mtcars) |>
recipes::step_select(recipes::all_predictors()) |>
recipes::prep()

expect_null(orbital(rec_exp$steps[[1]]))

rec <- recipes::recipe(mpg ~ ., data = mtcars0) |>
recipes::step_select(recipes::all_predictors()) |>
recipes::prep()

expect_null(orbital(rec$steps[[1]]))

expect_identical(orbital(rec), orbital(rec_exp))
# The step is predecated
expect_true(TRUE)
})

test_that("step_select only calculates what is sufficient", {
Expand Down
32 changes: 24 additions & 8 deletions tests/testthat/test-step_unknown.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ test_that("spark - step_unknown works", {
mtcars_unknown$carb <- letters[mtcars$carb]
mtcars_unknown[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_unknown) |>
rec <- recipes::recipe(
mpg ~ .,
data = mtcars_unknown,
strings_as_factors = FALSE
) |>
recipes::step_unknown(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars_unknown, !!!orbital_inline(orbital(rec)))

Expand All @@ -97,9 +101,13 @@ test_that("SQLite - step_unknown works", {
mtcars_unknown$carb <- letters[mtcars$carb]
mtcars_unknown[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_unknown) |>
rec <- recipes::recipe(
mpg ~ .,
data = mtcars_unknown,
strings_as_factors = FALSE
) |>
recipes::step_unknown(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars_unknown, !!!orbital_inline(orbital(rec)))

Expand All @@ -124,9 +132,13 @@ test_that("duckdb - step_unknown works", {
mtcars_unknown$carb <- letters[mtcars$carb]
mtcars_unknown[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_unknown) |>
rec <- recipes::recipe(
mpg ~ .,
data = mtcars_unknown,
strings_as_factors = FALSE
) |>
recipes::step_unknown(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars_unknown, !!!orbital_inline(orbital(rec)))

Expand All @@ -150,9 +162,13 @@ test_that("arrow - step_unknown works", {
mtcars_unknown$carb <- letters[mtcars$carb]
mtcars_unknown[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_unknown) |>
rec <- recipes::recipe(
mpg ~ .,
data = mtcars_unknown,
strings_as_factors = FALSE
) |>
recipes::step_unknown(recipes::all_nominal_predictors()) |>
recipes::prep(strings_as_factors = FALSE)
recipes::prep()

res <- dplyr::mutate(mtcars_unknown, !!!orbital_inline(orbital(rec)))

Expand Down
Loading