Skip to content

Commit dee4de4

Browse files
committed
fix: address n_train and ahead mismatch #290
1 parent 8c2a8a2 commit dee4de4

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

R/layer_residual_quantiles.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ slather.layer_residual_quantiles <-
123123
probs = object$quantile_levels, na.rm = TRUE
124124
))
125125
)
126+
# Check for NA
127+
if (any(sapply(r$dstn, is.na))) {
128+
cli::cli_abort("Quantiles could not be calculated due to missing residuals. Check your n_train and ahead values.")
129+
}
126130

127131
estimate <- components$predictions$.pred
128132
res <- tibble::tibble(

tests/testthat/test-layer_residual_quantiles.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,10 @@ test_that("Canned forecasters work with / without", {
9898
)
9999
)
100100
})
101+
102+
test_that("flatline_forecaster correctly errors when n_training < ahead", {
103+
expect_error(
104+
flatline_forecaster(jhu, "death_rate", args_list = flatline_args_list(ahead = 10, n_training = 9)),
105+
"Check your n_train and ahead values"
106+
)
107+
})

tests/testthat/test-target_date_bug.R

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# These tests address #290:
2+
# https://github.com/cmu-delphi/epipredict/issues/290
3+
14
library(dplyr)
25
train <- jhu_csse_daily_subset |>
36
filter(time_value >= as.Date("2021-10-01")) |>
@@ -13,7 +16,6 @@ test_that("flatline determines target_date where forecast_date exists", {
1316
ahead = 1L
1417
)
1518
)
16-
1719
# previously, if target_date existed, it could be
1820
# erroneously incremented by the ahead
1921
expect_identical(
@@ -24,9 +26,6 @@ test_that("flatline determines target_date where forecast_date exists", {
2426
flat$predictions$forecast_date,
2527
rep(as.Date("2021-12-31"), ngeos)
2628
)
27-
28-
# potentially resulted in NA predictions
29-
# see #290 https://github.com/cmu-delphi/epipredict/issues/290
3029
expect_true(all(!is.na(flat$predictions$.pred_distn)))
3130
expect_true(all(!is.na(flat$predictions$.pred)))
3231
})
@@ -50,9 +49,6 @@ test_that("arx_forecaster determines target_date where forecast_date exists", {
5049
arx$predictions$forecast_date,
5150
rep(as.Date("2021-12-31"), ngeos)
5251
)
53-
54-
# potentially resulted in NA predictions
55-
# see #290 https://github.com/cmu-delphi/epipredict/issues/290
5652
expect_true(all(!is.na(arx$predictions$.pred_distn)))
5753
expect_true(all(!is.na(arx$predictions$.pred)))
5854
})
@@ -67,7 +63,6 @@ test_that("arx_classifier determines target_date where forecast_date exists", {
6763
ahead = 1L
6864
)
6965
)
70-
7166
# previously, if target_date existed, it could be
7267
# erroneously incremented by the ahead
7368
expect_identical(
@@ -78,8 +73,5 @@ test_that("arx_classifier determines target_date where forecast_date exists", {
7873
arx$predictions$forecast_date,
7974
rep(as.Date("2021-12-31"), ngeos)
8075
)
81-
82-
# potentially resulted in NA predictions
83-
# see #290 https://github.com/cmu-delphi/epipredict/issues/290
8476
expect_true(all(!is.na(arx$predictions$.pred_class)))
8577
})

0 commit comments

Comments
 (0)