Skip to content

Commit 6b19bf0

Browse files
committed
fix warnings and empty tests
This is purely before any work on latency adjusting, and is just about geting the tests to run without warnings or skipped tests. Getting this involved: 1. renaming some lingering examples of p to probs and `q` to `quantile_levels` (and some `quantile_level`s to the plural) 2. Adding snapshots so the tests for printing in population_scaling work as intended (should probably be converted to cli_informs at some point) 3. removing the nearly empty `test-propagate_samples` which seems like something intended that was never finished. Probably want to add an issue if we actually want it done. 4. added a bunch of `edf`'s in unhappy `prep` steps
1 parent 7a4ea55 commit 6b19bf0

File tree

7 files changed

+97
-24
lines changed

7 files changed

+97
-24
lines changed

R/arx_forecaster.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ print.arx_fcast <- function(x, ...) {
289289
}
290290

291291
compare_quantile_args <- function(alist, tlist) {
292-
default_alist <- eval(formals(arx_args_list)$quantile_level)
293-
default_tlist <- eval(formals(quantile_reg)$quantile_level)
292+
default_alist <- eval(formals(arx_args_list)$quantile_levels)
293+
default_tlist <- eval(formals(quantile_reg)$quantile_levels)
294294
if (setequal(alist, default_alist)) {
295295
if (setequal(tlist, default_tlist)) {
296296
return(sort(unique(union(alist, tlist))))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# test joining by default columns
2+
3+
Code
4+
prep <- prep(r, jhu)
5+
Message
6+
Joining with `by = join_by(geo_value)`
7+
Joining with `by = join_by(geo_value)`
8+
9+
---
10+
11+
Code
12+
b <- bake(prep, jhu)
13+
Message
14+
Joining with `by = join_by(geo_value)`
15+
Joining with `by = join_by(geo_value)`
16+
17+
---
18+
19+
Code
20+
wf <- epi_workflow(r, parsnip::linear_reg()) %>% fit(jhu) %>% add_frosting(f)
21+
Message
22+
Joining with `by = join_by(geo_value)`
23+
Joining with `by = join_by(geo_value)`
24+
25+
---
26+
27+
Code
28+
p <- predict(wf, latest)
29+
Message
30+
Joining with `by = join_by(geo_value)`
31+
Joining with `by = join_by(geo_value)`
32+
Joining with `by = join_by(geo_value)`
33+
Joining with `by = join_by(geo_value)`
34+

tests/testthat/test-dist_quantiles.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ test_that("single dist_quantiles works, quantiles are accessible", {
2828

2929
test_that("quantile extrapolator works", {
3030
dstn <- dist_normal(c(10, 2), c(5, 10))
31-
qq <- extrapolate_quantiles(dstn, p = c(.25, 0.5, .75))
31+
qq <- extrapolate_quantiles(dstn, probs = c(.25, 0.5, .75))
3232
expect_s3_class(qq, "distribution")
3333
expect_s3_class(vctrs::vec_data(qq[1])[[1]], "dist_quantiles")
34-
expect_length(parameters(qq[1])$q[[1]], 3L)
34+
expect_length(parameters(qq[1])$quantile_levels[[1]], 3L)
3535

3636

3737
dstn <- dist_quantiles(list(1:4, 8:11), list(c(.2, .4, .6, .8)))
38-
qq <- extrapolate_quantiles(dstn, p = c(.25, 0.5, .75))
38+
qq <- extrapolate_quantiles(dstn, probs = c(.25, 0.5, .75))
3939
expect_s3_class(qq, "distribution")
4040
expect_s3_class(vctrs::vec_data(qq[1])[[1]], "dist_quantiles")
41-
expect_length(parameters(qq[1])$q[[1]], 7L)
41+
expect_length(parameters(qq[1])$quantile_levels[[1]], 7L)
4242
})
4343

4444
test_that("small deviations of quantile requests work", {

tests/testthat/test-population_scaling.R

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,53 @@ test_that("Postprocessing to get cases from case rate", {
207207

208208

209209
test_that("test joining by default columns", {
210-
skip()
210+
211+
jhu <- case_death_rate_subset %>%
212+
dplyr::filter(time_value > "2021-11-01", geo_value %in% c("ca", "ny")) %>%
213+
dplyr::select(geo_value, time_value, case_rate)
214+
215+
reverse_pop_data = data.frame(geo_value = c("ca", "ny"),
216+
values = c(1/20000, 1/30000))
217+
218+
r <- epi_recipe(jhu) %>%
219+
step_population_scaling(case_rate,
220+
df = reverse_pop_data,
221+
df_pop_col = "values",
222+
by = NULL,
223+
suffix = "_scaled") %>%
224+
step_epi_lag(case_rate_scaled, lag = c(0, 7, 14)) %>% # cases
225+
step_epi_ahead(case_rate_scaled, ahead = 7, role = "outcome") %>% # cases
226+
recipes::step_naomit(recipes::all_predictors()) %>%
227+
recipes::step_naomit(recipes::all_outcomes(), skip = TRUE)
228+
229+
expect_snapshot(prep <- prep(r, jhu))
230+
231+
expect_snapshot(b <- bake(prep, jhu))
232+
233+
f <- frosting() %>%
234+
layer_predict() %>%
235+
layer_threshold(.pred) %>%
236+
layer_naomit(.pred) %>%
237+
layer_population_scaling(.pred, df = reverse_pop_data,
238+
by = NULL,
239+
df_pop_col = "values")
240+
241+
expect_snapshot(wf <- epi_workflow(r,
242+
parsnip::linear_reg()) %>%
243+
fit(jhu) %>%
244+
add_frosting(f))
245+
246+
latest <- get_test_data(recipe = r,
247+
x = case_death_rate_subset %>%
248+
dplyr::filter(time_value > "2021-11-01",
249+
geo_value %in% c("ca", "ny")) %>%
250+
dplyr::select(geo_value, time_value, case_rate))
251+
252+
253+
expect_snapshot(p <- predict(wf, latest))
254+
255+
256+
211257
jhu <- case_death_rate_subset %>%
212258
dplyr::filter(time_value > "2021-11-01", geo_value %in% c("ca", "ny")) %>%
213259
dplyr::select(geo_value, time_value, case_rate)

tests/testthat/test-propagate_samples.R

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/testthat/test-step_growth_rate.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test_that("step_growth_rate works for a single signal", {
3434

3535
res <- r %>%
3636
step_growth_rate(value, horizon = 1) %>%
37-
prep() %>%
37+
prep(edf) %>%
3838
bake(edf)
3939
expect_equal(res$gr_1_rel_change_value, c(NA, 1 / 6:9))
4040

@@ -46,7 +46,7 @@ test_that("step_growth_rate works for a single signal", {
4646
r <- epi_recipe(edf)
4747
res <- r %>%
4848
step_growth_rate(value, horizon = 1) %>%
49-
prep() %>%
49+
prep(edf) %>%
5050
bake(edf)
5151
expect_equal(res$gr_1_rel_change_value, rep(c(NA, 1 / 6:9), each = 2))
5252
})
@@ -63,7 +63,7 @@ test_that("step_growth_rate works for a two signals", {
6363

6464
res <- r %>%
6565
step_growth_rate(v1, v2, horizon = 1) %>%
66-
prep() %>%
66+
prep(edf) %>%
6767
bake(edf)
6868
expect_equal(res$gr_1_rel_change_v1, c(NA, 1 / 6:9))
6969
expect_equal(res$gr_1_rel_change_v2, c(NA, 1 / 1:4))
@@ -76,7 +76,7 @@ test_that("step_growth_rate works for a two signals", {
7676
r <- epi_recipe(edf)
7777
res <- r %>%
7878
step_growth_rate(v1, v2, horizon = 1) %>%
79-
prep() %>%
79+
prep(edf) %>%
8080
bake(edf)
8181
expect_equal(res$gr_1_rel_change_v1, rep(c(NA, 1 / 6:9), each = 2))
8282
expect_equal(res$gr_1_rel_change_v2, rep(c(NA, 1 / 1:4), each = 2))

tests/testthat/test-step_lag_difference.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ test_that("step_lag_difference works for a single signal", {
2727

2828
res <- r %>%
2929
step_lag_difference(value, horizon = 1) %>%
30-
prep() %>%
30+
prep(edf) %>%
3131
bake(edf)
3232
expect_equal(res$lag_diff_1_value, c(NA, rep(1, 4)))
3333

3434
res <- r %>%
3535
step_lag_difference(value, horizon = 1:2) %>%
36-
prep() %>%
36+
prep(edf) %>%
3737
bake(edf)
3838
expect_equal(res$lag_diff_1_value, c(NA, rep(1, 4)))
3939
expect_equal(res$lag_diff_2_value, c(NA, NA, rep(2, 3)))
@@ -48,13 +48,13 @@ test_that("step_lag_difference works for a single signal", {
4848
r <- epi_recipe(edf)
4949
res <- r %>%
5050
step_lag_difference(value, horizon = 1) %>%
51-
prep() %>%
51+
prep(edf) %>%
5252
bake(edf)
5353
expect_equal(res$lag_diff_1_value, c(NA, NA, rep(1, 8)))
5454
})
5555

5656

57-
test_that("step_lag_difference works for a two signals", {
57+
test_that("step_lag_difference works for a two signal epi_df", {
5858
df <- data.frame(
5959
time_value = 1:5,
6060
geo_value = rep("a", 5),
@@ -65,7 +65,7 @@ test_that("step_lag_difference works for a two signals", {
6565

6666
res <- r %>%
6767
step_lag_difference(v1, v2, horizon = 1:2) %>%
68-
prep() %>%
68+
prep(edf) %>%
6969
bake(edf)
7070
expect_equal(res$lag_diff_1_v1, c(NA, rep(1, 4)))
7171
expect_equal(res$lag_diff_2_v1, c(NA, NA, rep(2, 3)))
@@ -80,7 +80,7 @@ test_that("step_lag_difference works for a two signals", {
8080
r <- epi_recipe(edf)
8181
res <- r %>%
8282
step_lag_difference(v1, v2, horizon = 1:2) %>%
83-
prep() %>%
83+
prep(edf) %>%
8484
bake(edf)
8585
expect_equal(res$lag_diff_1_v1, rep(c(NA, rep(1, 4)), each = 2))
8686
expect_equal(res$lag_diff_2_v1, rep(c(NA, NA, rep(2, 3)), each = 2))

0 commit comments

Comments
 (0)