Skip to content

Commit

Permalink
Merge pull request #152 from tidymodels/more-snapshots
Browse files Browse the repository at this point in the history
More snapshots
  • Loading branch information
EmilHvitfeldt authored Sep 24, 2024
2 parents 0105665 + e172370 commit e8c9b21
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 86 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
- {os: macos-latest, r: 'release'}

- {os: windows-latest, r: 'release'}
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}
# use 4.1 to check with rtools40's older compiler
- {os: windows-latest, r: '4.1'}

Expand Down
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ URL: https://github.com/tidymodels/themis, https://themis.tidymodels.org
BugReports: https://github.com/tidymodels/themis/issues
Depends:
R (>= 3.6),
recipes (>= 1.0.4)
recipes (>= 1.1.0.9000)
Imports:
gower,
lifecycle (>= 1.0.3),
Expand All @@ -41,6 +41,8 @@ Suggests:
ggplot2,
modeldata,
testthat (>= 3.0.0)
Remotes:
tidymodels/recipes
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/adasyn.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
Caused by error in `prep()`:
! Cannot have any missing values. NAs found ind: Job.

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_adasyn()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/bsmote.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
Caused by error in `prep()`:
! Cannot have any missing values. NAs found ind: Job.

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_bsmote()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/downsample.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
-- Operations
* Down-sampling based on: class | Trained, ignored weights

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_downsample()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/nearmiss.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
Caused by error in `prep()`:
! Cannot have any missing values. NAs found ind: Job.

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_nearmiss()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/rose.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
Caused by error in `prep()`:
! `x` must only have 2 levels.

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_rose()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/smote.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
Caused by error in `prep()`:
! Cannot have any missing values. NAs found ind: Job.

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_smote()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
44 changes: 44 additions & 0 deletions tests/testthat/_snaps/smotenc.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
# errors if there isn't enough data

Code
recipe(Status ~ Age, data = credit_data0) %>% step_smotenc(Status) %>% prep()
Condition
Error in `step_smotenc()`:
Caused by error in `smotenc_impl()`:
! Not enough observations of 'dummy' to perform SMOTE.

# bad data

Code
rec %>% step_smotenc(x) %>% prep()
Condition
Error in `step_smotenc()`:
Caused by error in `prep()`:
! `x` should be a factor variable.

---

Code
rec %>% step_smotenc(class, id) %>% prep()
Condition
Error in `step_smotenc()`:
Caused by error in `prep()`:
! The selector should select at most a single variable

# NA in response

Code
recipe(Job ~ Age, data = credit_data) %>% step_smotenc(Job) %>% prep()
Condition
Error in `step_smotenc()`:
Caused by error in `prep()`:
! Cannot have any missing values. NAs found ind: Job.

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_smotenc()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/tomek.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
Caused by error in `prep()`:
! Cannot have any missing values. NAs found ind: Status.

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_tomek()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/upsample.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
-- Operations
* Up-sampling based on: class | Trained, ignored weights

# bake method errors when needed non-standard role columns are missing

Code
bake(trained, new_data = circle_example[, -3])
Condition
Error in `step_upsample()`:
! The following required column is missing from `new_data`: class.

# empty printing

Code
Expand Down
13 changes: 7 additions & 6 deletions tests/testthat/test-adasyn.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test_that("basic usage", {

expect_equal(sort(te_xtab), sort(og_xtab))

expect_warning(prep(rec1), NA)
expect_no_warning(prep(rec1))
})

test_that("bad data", {
Expand Down Expand Up @@ -129,11 +129,10 @@ test_that("ratio value works when oversampling", {

test_that("allows multi-class", {
data("credit_data")
expect_error(
expect_no_error(
recipe(Home ~ Age + Income + Assets, data = credit_data) %>%
step_impute_mean(Income, Assets) %>%
step_adasyn(Home),
NA
step_adasyn(Home)
)
})

Expand Down Expand Up @@ -250,8 +249,10 @@ test_that("bake method errors when needed non-standard role columns are missing"

trained <- prep(rec, training = circle_example, verbose = FALSE)

expect_error(bake(trained, new_data = circle_example[, -3]),
class = "new_data_missing_column")
expect_snapshot(
error = TRUE,
bake(trained, new_data = circle_example[, -3]),
)
})

test_that("empty printing", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-adasyn_impl.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
circle_example_num <- circle_example[, c("x", "y", "class")]

test_that("adasyn() interfaces correctly", {
expect_error(adasyn(circle_example_num, var = "class"), NA)
expect_no_error(adasyn(circle_example_num, var = "class"))

expect_snapshot(error = TRUE,
adasyn(circle_example_num, var = "Class")
Expand Down
15 changes: 8 additions & 7 deletions tests/testthat/test-bsmote.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test_that("basic usage", {

expect_equal(sort(te_xtab), sort(og_xtab))

expect_warning(prep(rec1), NA)
expect_no_warning(prep(rec1))
})

test_that("basic usage", {
Expand All @@ -43,7 +43,7 @@ test_that("basic usage", {

expect_equal(sort(te_xtab), sort(og_xtab))

expect_warning(prep(rec1), NA)
expect_no_warning(prep(rec1))
})

test_that("bad data", {
Expand Down Expand Up @@ -161,11 +161,10 @@ test_that("ratio value works when oversampling", {

test_that("allows multi-class", {
data("credit_data")
expect_error(
expect_no_error(
recipe(Home ~ Age + Income + Assets, data = credit_data) %>%
step_impute_mean(Income, Assets) %>%
step_bsmote(Home),
NA
step_bsmote(Home)
)
})

Expand Down Expand Up @@ -334,8 +333,10 @@ test_that("bake method errors when needed non-standard role columns are missing"

trained <- prep(rec, training = circle_example, verbose = FALSE)

expect_error(bake(trained, new_data = circle_example[, -3]),
class = "new_data_missing_column")
expect_snapshot(
error = TRUE,
bake(trained, new_data = circle_example[, -3])
)
})

test_that("empty printing", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-bsmote_impl.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
circle_example_num <- circle_example[, c("x", "y", "class")]

test_that("bsmote() interfaces correctly", {
expect_error(bsmote(circle_example_num, var = "class"), NA)
expect_no_error(bsmote(circle_example_num, var = "class"))

expect_snapshot(error = TRUE,
bsmote(circle_example_num, var = "Class")
Expand Down
13 changes: 7 additions & 6 deletions tests/testthat/test-downsample.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("basic usage", {

expect_equal(sort(te_xtab), sort(og_xtab))

expect_warning(prep(rec1), NA)
expect_no_warning(prep(rec1))
})

test_that("bad data", {
Expand Down Expand Up @@ -99,11 +99,10 @@ test_that("ratio value works when undersampling", {

test_that("allows multi-class", {
data("credit_data")
expect_error(
expect_no_error(
recipe(Home ~ Age + Income + Assets, data = credit_data) %>%
step_impute_mean(Income, Assets) %>%
step_downsample(Home),
NA
step_downsample(Home)
)
})

Expand Down Expand Up @@ -236,8 +235,10 @@ test_that("bake method errors when needed non-standard role columns are missing"

trained <- prep(rec, training = circle_example, verbose = FALSE)

expect_error(bake(trained, new_data = circle_example[, -3]),
class = "new_data_missing_column")
expect_snapshot(
error = TRUE,
bake(trained, new_data = circle_example[, -3])
)
})

test_that("empty printing", {
Expand Down
13 changes: 7 additions & 6 deletions tests/testthat/test-nearmiss.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test_that("basic usage", {

expect_equal(sort(te_xtab), sort(og_xtab))

expect_warning(prep(rec1), NA)
expect_no_warning(prep(rec1))
})

test_that("bad data", {
Expand Down Expand Up @@ -99,11 +99,10 @@ test_that("ratio value works when undersampling", {

test_that("allows multi-class", {
data("credit_data")
expect_error(
expect_no_error(
recipe(Home ~ Age + Income + Assets, data = credit_data) %>%
step_impute_mean(Income, Assets) %>%
step_nearmiss(Home),
NA
step_nearmiss(Home)
)
})

Expand Down Expand Up @@ -200,8 +199,10 @@ test_that("bake method errors when needed non-standard role columns are missing"

trained <- prep(rec, training = circle_example, verbose = FALSE)

expect_error(bake(trained, new_data = circle_example[, -3]),
class = "new_data_missing_column")
expect_snapshot(
error = TRUE,
bake(trained, new_data = circle_example[, -3])
)
})

test_that("empty printing", {
Expand Down
Loading

0 comments on commit e8c9b21

Please sign in to comment.