From 4231998aef0f366b1b6bafc9883a79dd24d47e9e Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Thu, 10 Apr 2025 14:11:07 -0700 Subject: [PATCH 1/3] wip: epi_df pivot_longer --- tests/testthat/test-pivot_quantiles.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/testthat/test-pivot_quantiles.R b/tests/testthat/test-pivot_quantiles.R index d32c1649..87597c97 100644 --- a/tests/testthat/test-pivot_quantiles.R +++ b/tests/testthat/test-pivot_quantiles.R @@ -45,6 +45,11 @@ test_that("quantile pivotting longer behaves", { expect_length(pivot_quantiles_longer(tib, d1), 4L) expect_identical(nrow(pivot_quantiles_longer(tib, d1)), 6L) expect_identical(pivot_quantiles_longer(tib, d1)$d1_value, c(1:3, 2:4)) + + # add quantile_level to epi_df keys, if epi_df + tib <- tibble(geo_value = c("a", "b"), time_value = as.Date(c("2021-01-01", "2021-01-02")), d1 = d1, d2 = d2) + epi_df <- tib %>% as_epi_df() %>% pivot_quantiles_longer(d1) + expect_equal(key_colnames(epi_df), c("geo_value", "time_value", "quantile_level")) }) test_that("nested_quantiles is deprecated, but works where possible", { From b4dc6a578ca2009c0adb24cb5578eefce0759233 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Thu, 10 Apr 2025 15:10:20 -0700 Subject: [PATCH 2/3] enh: pivot_quantiles_longer adds quantile_level to epi_df other_keys --- R/pivot_quantiles.R | 6 +++++- tests/testthat/test-pivot_quantiles.R | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/R/pivot_quantiles.R b/R/pivot_quantiles.R index e4b5b332..3ed9ab06 100644 --- a/R/pivot_quantiles.R +++ b/R/pivot_quantiles.R @@ -62,8 +62,12 @@ pivot_quantiles_longer <- function(.data, ...) { long_tib <- as_tibble(.data[[col]]) .data <- select(.data, !all_of(col)) names(long_tib)[1:2] <- c(glue::glue("{col}_value"), glue::glue("{col}_quantile_level")) - left_join(.data, long_tib, by = ".row") %>% + out <- left_join(.data, long_tib, by = ".row") %>% select(!.row) + if (inherits(.data, "epi_df")) { + attr(out, "metadata")$other_keys <- c(attr(.data, "metadata")$other_keys, glue::glue("{col}_quantile_level")) + } + out } #' Pivot a column containing `quantile_pred` wider diff --git a/tests/testthat/test-pivot_quantiles.R b/tests/testthat/test-pivot_quantiles.R index 87597c97..b8253286 100644 --- a/tests/testthat/test-pivot_quantiles.R +++ b/tests/testthat/test-pivot_quantiles.R @@ -46,10 +46,10 @@ test_that("quantile pivotting longer behaves", { expect_identical(nrow(pivot_quantiles_longer(tib, d1)), 6L) expect_identical(pivot_quantiles_longer(tib, d1)$d1_value, c(1:3, 2:4)) - # add quantile_level to epi_df keys, if epi_df + # add quantile_level to epi_df other_keys, if epi_df tib <- tibble(geo_value = c("a", "b"), time_value = as.Date(c("2021-01-01", "2021-01-02")), d1 = d1, d2 = d2) epi_df <- tib %>% as_epi_df() %>% pivot_quantiles_longer(d1) - expect_equal(key_colnames(epi_df), c("geo_value", "time_value", "quantile_level")) + expect_equal(key_colnames(epi_df), c("geo_value","d1_quantile_level", "time_value")) }) test_that("nested_quantiles is deprecated, but works where possible", { From f7c8f8c344c8cbc8b072dd336077963b301eaec5 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Thu, 10 Apr 2025 15:13:25 -0700 Subject: [PATCH 3/3] doc: version and news --- DESCRIPTION | 2 +- NEWS.md | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 81a35b30..ab7df96f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: epipredict Title: Basic epidemiology forecasting methods -Version: 0.1.15 +Version: 0.1.16 Authors@R: c( person("Daniel J.", "McDonald", , "daniel@stat.ubc.ca", role = c("aut", "cre")), person("Ryan", "Tibshirani", , "ryantibs@cmu.edu", role = "aut"), diff --git a/NEWS.md b/NEWS.md index de698ee9..277943b2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,12 +12,12 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat `data(, package = "epidatasets")`, `epidatasets::` or, after loading the package, the name of the dataset alone (#382). - `step_adjust_latency()` no longer allows empty column selection. -- Addresses upstream breaking changes from cmu-delphi/epiprocess#595 (`growth_rate()`). +- Addresses upstream breaking changes from cmu-delphi/epiprocess#595 (`growth_rate()`). `step_growth_rate()` has lost its `additional_gr_args_list` argument and now has an `na_rm` argument. - Moves `epiprocess` out of depends (#440). No internals have changed, but downstream users may need to add `library(epiprocess)` to existing code. -- Removes dependence on the `distributional` package, replacing the quantiles +- Removes dependence on the `distributional` package, replacing the quantiles with `hardhat::quantile_pred()`. Some associated functions are deprecated with `lifecycle` messages. - Rename `check_enough_train_data()` to `check_enough_data()`, and generalize it @@ -38,6 +38,8 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat - Replace `dist_quantiles()` with `hardhat::quantile_pred()` - Allow `quantile()` to threshold to an interval if desired (#434) - `arx_forecaster()` detects if there's enough data to predict +- `pivot_quantiles_longer()` now appropriately adds `quantile_level` to the + `epi_df` other keys ## Bug fixes