Skip to content

Commit

Permalink
Merge pull request #43 from tidymodels/test-arrow
Browse files Browse the repository at this point in the history
test on arrow tables
  • Loading branch information
EmilHvitfeldt authored Jul 27, 2024
2 parents 6043bba + 345a566 commit 70a4adf
Show file tree
Hide file tree
Showing 47 changed files with 873 additions and 26 deletions.
26 changes: 0 additions & 26 deletions tests/testthat/_snaps/dt.new.md

This file was deleted.

22 changes: 22 additions & 0 deletions tests/testthat/test-step_adasyn.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,25 @@ test_that("duckdb - step_adasyn works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_adasyn works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("arrow")

mtcars_adasyn <- dplyr::as_tibble(mtcars)
mtcars_adasyn$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars_adasyn) %>%
themis::step_adasyn(vs, skip = TRUE) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars_adasyn)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
20 changes: 20 additions & 0 deletions tests/testthat/test-step_bin2factor.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,23 @@ test_that("duckdb - step_bin2factor works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_bin2factor works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars <- dplyr::as_tibble(mtcars)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
recipes::step_bin2factor(vs, am) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
20 changes: 20 additions & 0 deletions tests/testthat/test-step_boxcox.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,23 @@ test_that("duckdb - step_BoxCox works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_BoxCox works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars <- dplyr::as_tibble(mtcars)

rec <- recipes::recipe(~ ., data = mtcars) %>%
recipes::step_BoxCox(mpg, disp) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
22 changes: 22 additions & 0 deletions tests/testthat/test-step_bsmote.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,25 @@ test_that("duckdb - step_bsmote works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_bsmote works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("arrow")

mtcars_bsmote <- dplyr::as_tibble(mtcars)
mtcars_bsmote$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars_bsmote) %>%
themis::step_bsmote(vs, skip = TRUE) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars_bsmote)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
20 changes: 20 additions & 0 deletions tests/testthat/test-step_center.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,23 @@ test_that("duckdb - step_center works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_center works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars <- dplyr::as_tibble(mtcars)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
recipes::step_center(recipes::all_predictors()) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
5 changes: 5 additions & 0 deletions tests/testthat/test-step_corr.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ test_that("SQLite - step_corr works", {
test_that("duckdb - step_corr works", {
# Isn't needed as `step_corr()` doesn't produce code
expect_true(TRUE)
})

test_that("arrow - step_corr works", {
# Isn't needed as `step_corr()` doesn't produce code
expect_true(TRUE)
})
23 changes: 23 additions & 0 deletions tests/testthat/test-step_discretize.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,26 @@ test_that("duckdb - step_discretize works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_discretize works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars_discretize <- dplyr::as_tibble(mtcars)
mtcars_discretize[1, ] <- NA

suppressWarnings(
rec <- recipes::recipe(mpg ~ ., data = mtcars_discretize) %>%
recipes::step_discretize(mpg, disp, min_unique = 4) %>%
recipes::prep()
)

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

mtcars_tbl <- arrow::as_arrow_table(mtcars_discretize)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
22 changes: 22 additions & 0 deletions tests/testthat/test-step_downsample.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,25 @@ test_that("duckdb - step_downsample works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_downsample works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("arrow")

mtcars_downsample <- dplyr::as_tibble(mtcars)
mtcars_downsample$vs <- as.factor(mtcars$vs)

rec <- recipes::recipe(mpg ~ ., data = mtcars_downsample) %>%
themis::step_downsample(vs, skip = TRUE) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars_downsample)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
23 changes: 23 additions & 0 deletions tests/testthat/test-step_dummy.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,27 @@ test_that("duckdb - step_dummy works", {
expect_equal(res_new, exp)

DBI::dbDisconnect(con)
})

test_that("arrow - step_dummy works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars1 <- dplyr::as_tibble(mtcars)

mtcars1$gear <- as.character(mtcars1$gear)
mtcars1$carb <- as.character(mtcars1$carb)

rec <- recipes::recipe(mpg ~ ., data = mtcars1) %>%
recipes::step_dummy(recipes::all_nominal_predictors()) %>%
recipes::prep()

exp <- dplyr::mutate(mtcars1, !!!orbital_inline(orbital(rec)))

mtcars_tbl <- arrow::as_arrow_table(mtcars1)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, exp)
})
5 changes: 5 additions & 0 deletions tests/testthat/test-step_filter_missing.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ test_that("SQLite - step_filter_missing works", {
test_that("duckdb - step_filter_missing works", {
# Isn't needed as `step_filter_missing()` doesn't produce code
expect_true(TRUE)
})

test_that("arrow - step_filter_missing works", {
# Isn't needed as `step_filter_missing()` doesn't produce code
expect_true(TRUE)
})
21 changes: 21 additions & 0 deletions tests/testthat/test-step_impute_mean.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,24 @@ test_that("duckdb - step_impute_mean works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_impute_mean works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars_impute_mean <- dplyr::as_tibble(mtcars)
mtcars_impute_mean[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_mean) %>%
recipes::step_impute_mean(recipes::all_predictors()) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars_impute_mean)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
21 changes: 21 additions & 0 deletions tests/testthat/test-step_impute_median.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,24 @@ test_that("duckdb - step_impute_median works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_impute_median works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars_impute_median <- dplyr::as_tibble(mtcars)
mtcars_impute_median[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_impute_median) %>%
recipes::step_impute_median(recipes::all_predictors()) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars_impute_median)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
23 changes: 23 additions & 0 deletions tests/testthat/test-step_impute_mode.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,26 @@ test_that("duckdb - step_impute_mode works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_impute_mode works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars_impute_mode <- dplyr::as_tibble(mtcars)
mtcars_impute_mode$gear <- letters[mtcars$gear]
mtcars_impute_mode$carb <- letters[mtcars$carb]
mtcars_impute_mode[2:4, ] <- NA

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

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

mtcars_tbl <- arrow::as_arrow_table(mtcars_impute_mode)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
21 changes: 21 additions & 0 deletions tests/testthat/test-step_indicate_na.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,24 @@ test_that("duckdb - step_indicate_na works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_indicate_na works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars_indicate_na <- dplyr::as_tibble(mtcars)
mtcars_indicate_na[2:4, ] <- NA

rec <- recipes::recipe(mpg ~ ., data = mtcars_indicate_na) %>%
recipes::step_indicate_na(recipes::all_predictors()) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars_indicate_na)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
20 changes: 20 additions & 0 deletions tests/testthat/test-step_intercept.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,23 @@ test_that("duckdb - step_intercept works", {

DBI::dbDisconnect(con)
})

test_that("arrow - step_intercept works", {
skip_if_not_installed("recipes")
skip_if_not_installed("arrow")

mtcars <- dplyr::as_tibble(mtcars)

rec <- recipes::recipe(mpg ~ ., data = mtcars) %>%
recipes::step_intercept(value = 5) %>%
recipes::prep()

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

mtcars_tbl <- arrow::as_arrow_table(mtcars)

res_new <- dplyr::mutate(mtcars_tbl, !!!orbital_inline(orbital(rec))) %>%
dplyr::collect()

expect_equal(res_new, res)
})
Loading

0 comments on commit 70a4adf

Please sign in to comment.