Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test data.table with dtplyr #42

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Imports:
Suggests:
arrow,
DBI,
data.table,
dbplyr,
dtplyr,
duckdb,
Expand Down
26 changes: 0 additions & 26 deletions tests/testthat/_snaps/dt.new.md

This file was deleted.

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

DBI::dbDisconnect(con)
})

test_that("data.table - step_adasyn works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars_adasyn)

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_bin2factor.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,25 @@ test_that("duckdb - step_bin2factor works", {

DBI::dbDisconnect(con)
})

test_that("data.table - step_bin2factor works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars)

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_boxcox.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,26 @@ test_that("duckdb - step_BoxCox works", {

DBI::dbDisconnect(con)
})


test_that("data.table - step_BoxCox works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars)

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

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

DBI::dbDisconnect(con)
})

test_that("data.table - step_bsmote works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars_bsmote)

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_center.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,25 @@ test_that("duckdb - step_center works", {

DBI::dbDisconnect(con)
})

test_that("data.table - step_center works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(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("data.table - step_corr works", {
# Isn't needed as `step_corr()` doesn't produce code
expect_true(TRUE)
})
25 changes: 25 additions & 0 deletions tests/testthat/test-step_discretize.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,28 @@ test_that("duckdb - step_discretize works", {

DBI::dbDisconnect(con)
})

test_that("data.table - step_discretize works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars_discretize)

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

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

DBI::dbDisconnect(con)
})

test_that("data.table - step_downsample works", {
skip_if_not_installed("recipes")
skip_if_not_installed("themis")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars_downsample)

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

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

DBI::dbDisconnect(con)
})

test_that("data.table - step_dummy works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(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("data.table - step_filter_missing works", {
# Isn't needed as `step_filter_missing()` doesn't produce code
expect_true(TRUE)
})
23 changes: 23 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,26 @@ test_that("duckdb - step_impute_mean works", {

DBI::dbDisconnect(con)
})

test_that("data.table - step_impute_mean works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars_impute_mean)

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_median.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,26 @@ test_that("duckdb - step_impute_median works", {

DBI::dbDisconnect(con)
})

test_that("data.table - step_impute_median works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars_impute_median)

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

expect_equal(res_new, res)
})
25 changes: 25 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,28 @@ test_that("duckdb - step_impute_mode works", {

DBI::dbDisconnect(con)
})

test_that("data.table - step_impute_mode works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars_impute_mode)

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_indicate_na.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,26 @@ test_that("duckdb - step_indicate_na works", {

DBI::dbDisconnect(con)
})

test_that("data.table - step_indicate_na works", {
skip_if_not_installed("recipes")
skip_if_not_installed("dtplyr")

`:=` <- data.table::`:=`

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 <- dtplyr::lazy_dt(mtcars_indicate_na)

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

expect_equal(res_new, res)
})
Loading
Loading