Skip to content

Commit 9dd8c8a

Browse files
authored
Merge pull request #48 from ChloeYou/main
Fix grouping issue in test data
2 parents ba0d8b5 + 020378a commit 9dd8c8a

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

R/get_test_data.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ get_test_data <- function(recipe, x){
4242
stop("insufficient training data")
4343
}
4444

45+
groups <- epi_keys(recipe)[epi_keys(recipe) != "time_value"]
46+
4547
test_data <- x %>%
4648
dplyr::filter(
4749
dplyr::if_any(
4850
.cols = recipe$term_info$variable[which(recipe$var_info$role == 'raw')],
4951
.fns = ~ !is.na(.x)
5052
)
5153
) %>%
52-
epiprocess::group_by(geo_value) %>%
54+
epiprocess::group_by(dplyr::across(dplyr::all_of(groups))) %>%
5355
dplyr::slice_tail(n = max(max_lags) + 1) %>%
5456
epiprocess::ungroup()
5557

tests/testthat/test-get_test_data.R

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
test_that("return expected number of rows", {
1+
library(dplyr)
2+
test_that("return expected number of rows and returned dataset is ungrouped", {
23
r <- epi_recipe(case_death_rate_subset) %>%
34
step_epi_ahead(death_rate, ahead = 7) %>%
45
step_epi_lag(death_rate, lag = c(0, 7, 14, 21, 28)) %>%
@@ -10,6 +11,8 @@ test_that("return expected number of rows", {
1011

1112
expect_equal(nrow(test),
1213
dplyr::n_distinct(case_death_rate_subset$geo_value)* 29)
14+
15+
expect_false(dplyr::is.grouped_df(test))
1316
})
1417

1518

@@ -35,3 +38,4 @@ test_that("expect error that geo_value or time_value does not exist", {
3538

3639
expect_error(get_test_data(recipe = r, x = wrong_epi_df))
3740
})
41+

tests/testthat/test-layer_predict.R

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ test_that("predict layer works alone", {
2020
expect_s3_class(p, "epi_df")
2121
expect_equal(nrow(p), 108L)
2222
expect_named(p, c("time_value", "geo_value", ".pred"))
23-
2423
})
2524

2625
test_that("prediction with interval works", {

0 commit comments

Comments
 (0)