Skip to content

Commit 34cb6ed

Browse files
authored
Merge pull request #386 from cmu-delphi/ds/epiprocess-0.9.0
fix: update for compatibility with epiprocess==0.9.0
2 parents cd12775 + 374cb2f commit 34cb6ed

29 files changed

+200
-191
lines changed

.Rbuildignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
^DEVELOPMENT\.md$
2020
^doc$
2121
^Meta$
22-
^.lintr$
22+
^.lintr$
23+
^.venv$

DESCRIPTION

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: epipredict
22
Title: Basic epidemiology forecasting methods
3-
Version: 0.0.20
3+
Version: 0.0.21
44
Authors@R: c(
55
person("Daniel", "McDonald", , "[email protected]", role = c("aut", "cre")),
66
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),
@@ -23,8 +23,7 @@ URL: https://github.com/cmu-delphi/epipredict/,
2323
https://cmu-delphi.github.io/epipredict
2424
BugReports: https://github.com/cmu-delphi/epipredict/issues/
2525
Depends:
26-
epiprocess (>= 0.8.0),
27-
epiprocess (< 0.9.0),
26+
epiprocess (>= 0.9.0),
2827
parsnip (>= 1.0.0),
2928
R (>= 3.5.0)
3029
Imports:

R/autoplot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ autoplot.epi_workflow <- function(
131131
if (length(extra_keys) == 0L) extra_keys <- NULL
132132
edf <- as_epi_df(edf,
133133
as_of = object$fit$meta$as_of,
134-
additional_metadata = list(other_keys = extra_keys)
134+
other_keys = extra_keys %||% character()
135135
)
136136
if (is.null(predictions)) {
137137
return(autoplot(

R/cdc_baseline_forecaster.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
#' mutate(deaths = pmax(death_rate / 1e5 * pop * 7, 0)) %>%
3030
#' select(-pop, -death_rate) %>%
3131
#' group_by(geo_value) %>%
32-
#' epi_slide(~ sum(.$deaths), before = 6, new_col_name = "deaths") %>%
32+
#' epi_slide(~ sum(.$deaths), .window_size = 7, .new_col_name = "deaths_7dsum") %>%
3333
#' ungroup() %>%
3434
#' filter(weekdays(time_value) == "Saturday")
3535
#'
36-
#' cdc <- cdc_baseline_forecaster(weekly_deaths, "deaths")
36+
#' cdc <- cdc_baseline_forecaster(weekly_deaths, "deaths_7dsum")
3737
#' preds <- pivot_quantiles_wider(cdc$predictions, .pred_distn)
3838
#'
3939
#' if (require(ggplot2)) {
@@ -47,7 +47,7 @@
4747
#' geom_line(aes(y = .pred), color = "orange") +
4848
#' geom_line(
4949
#' data = weekly_deaths %>% filter(geo_value %in% four_states),
50-
#' aes(x = time_value, y = deaths)
50+
#' aes(x = time_value, y = deaths_7dsum)
5151
#' ) +
5252
#' scale_x_date(limits = c(forecast_date - 90, forecast_date + 30)) +
5353
#' labs(x = "Date", y = "Weekly deaths") +

R/epi_recipe.R

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ epi_recipe.epi_df <-
9595
keys <- key_colnames(x) # we know x is an epi_df
9696

9797
var_info <- tibble(variable = vars)
98-
key_roles <- c("geo_value", "time_value", rep("key", length(keys) - 2))
98+
key_roles <- c("geo_value", rep("key", length(keys) - 2), "time_value")
9999

100100
## Check and add roles when available
101101
if (!is.null(roles)) {
@@ -499,8 +499,11 @@ prep.epi_recipe <- function(
499499
if (!is_epi_df(training)) {
500500
# tidymodels killed our class
501501
# for now, we only allow step_epi_* to alter the metadata
502-
training <- dplyr::dplyr_reconstruct(
503-
as_epi_df(training), before_template
502+
metadata <- attr(before_template, "metadata")
503+
training <- as_epi_df(
504+
training,
505+
as_of = metadata$as_of,
506+
other_keys = metadata$other_keys %||% character()
504507
)
505508
}
506509
training <- dplyr::relocate(training, all_of(key_colnames(training)))
@@ -579,8 +582,7 @@ bake.epi_recipe <- function(object, new_data, ..., composition = "epi_df") {
579582
new_data <- as_epi_df(
580583
new_data,
581584
as_of = meta$as_of,
582-
# avoid NULL if meta is from saved older epi_df:
583-
additional_metadata = meta$additional_metadata %||% list()
585+
other_keys = meta$other_keys %||% character()
584586
)
585587
}
586588
new_data

R/epi_workflow.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ is_epi_workflow <- function(x) {
9898
fit.epi_workflow <- function(object, data, ..., control = workflows::control_workflow()) {
9999
object$fit$meta <- list(
100100
max_time_value = max(data$time_value),
101-
as_of = attributes(data)$metadata$as_of
101+
as_of = attr(data, "metadata")$as_of,
102+
other_keys = attr(data, "metadata")$other_keys
102103
)
103104
object$original_data <- data
104105

R/flusight_hub_formatter.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ abbr_to_location <- function(abbr) {
6767
#' mutate(deaths = pmax(death_rate / 1e5 * pop * 7, 0)) %>%
6868
#' select(-pop, -death_rate) %>%
6969
#' group_by(geo_value) %>%
70-
#' epi_slide(~ sum(.$deaths), before = 6, new_col_name = "deaths") %>%
70+
#' epi_slide(~ sum(.$deaths), .window_size = 7, .new_col_name = "deaths_7dsum") %>%
7171
#' ungroup() %>%
7272
#' filter(weekdays(time_value) == "Saturday")
7373
#'
74-
#' cdc <- cdc_baseline_forecaster(weekly_deaths, "deaths")
74+
#' cdc <- cdc_baseline_forecaster(weekly_deaths, "deaths_7dsum")
7575
#' flusight_hub_formatter(cdc)
7676
#' flusight_hub_formatter(cdc, target = "wk inc covid deaths")
7777
#' flusight_hub_formatter(cdc, target = paste(horizon, "wk inc covid deaths"))

R/key_colnames.R

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#' @export
22
key_colnames.recipe <- function(x, ...) {
3-
possible_keys <- c("geo_value", "time_value", "key")
4-
keys <- x$var_info$variable[x$var_info$role %in% possible_keys]
5-
keys[order(match(keys, possible_keys))] %||% character(0L)
3+
geo_key <- x$var_info$variable[x$var_info$role %in% "geo_value"]
4+
time_key <- x$var_info$variable[x$var_info$role %in% "time_value"]
5+
keys <- x$var_info$variable[x$var_info$role %in% "key"]
6+
c(geo_key, keys, time_key) %||% character(0L)
67
}
78

89
#' @export
910
key_colnames.epi_workflow <- function(x, ...) {
1011
# safer to look at the mold than the preprocessor
1112
mold <- hardhat::extract_mold(x)
12-
possible_keys <- c("geo_value", "time_value", "key")
1313
molded_names <- names(mold$extras$roles)
14-
keys <- map(mold$extras$roles[molded_names %in% possible_keys], names)
15-
keys <- unname(unlist(keys))
16-
keys[order(match(keys, possible_keys))] %||% character(0L)
14+
geo_key <- names(mold$extras$roles[molded_names %in% "geo_value"]$geo_value)
15+
time_key <- names(mold$extras$roles[molded_names %in% "time_value"]$time_value)
16+
keys <- names(mold$extras$roles[molded_names %in% "key"]$key)
17+
c(geo_key, keys, time_key) %||% character(0L)
1718
}
1819

1920
kill_time_value <- function(v) {

R/layer_add_forecast_date.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ slather.layer_add_forecast_date <- function(object, components, workflow,
104104
workflows::extract_preprocessor(workflow)$template, "metadata"
105105
)$time_type
106106
if (expected_time_type == "week") expected_time_type <- "day"
107+
if (expected_time_type == "integer") expected_time_type <- "year"
107108
validate_date(
108109
forecast_date, expected_time_type,
109110
call = rlang::expr(layer_add_forecast_date())

R/layer_add_target_date.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ slather.layer_add_target_date <- function(object, components, workflow,
9090
workflows::extract_preprocessor(workflow)$template, "metadata"
9191
)$time_type
9292
if (expected_time_type == "week") expected_time_type <- "day"
93+
if (expected_time_type == "integer") expected_time_type <- "year"
9394

9495
if (!is.null(object$target_date)) {
9596
target_date <- object$target_date

0 commit comments

Comments
 (0)