Skip to content

Commit ef45cf1

Browse files
committed
Fixup merge
- max(self$DT$time_value) -> max_time - merge updates to as_of test: both - test that doesn't mutate key - use custom test archive, not archive_cases_dv_subset
1 parent c5eaf14 commit ef45cf1

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

R/archive.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ epi_archive =
416416
cat(sprintf("* %-14s = %s\n", "min time value",
417417
min_time))
418418
cat(sprintf("* %-14s = %s\n", "max time value",
419-
max(self$DT$time_value)))
419+
max_time))
420420
cat(sprintf("* %-14s = %s\n", "first version with update",
421421
min(self$DT$version)))
422422
cat(sprintf("* %-14s = %s\n", "last version with update",

tests/testthat/test-methods-epi_archive.R

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,38 @@ test_that("Warning against max_version being same as edf's max version",{
2323
})
2424

2525
test_that("as_of properly grabs the data and doesn't mutate key",{
26-
old_key = data.table::key(ea$DT)
2726

28-
df_as_of <- ea %>%
29-
epix_as_of(max_version = as.Date("2020-07-01")) %>%
30-
na.omit() %>%
31-
as.data.frame()
32-
33-
df_filter <- ea$DT %>%
34-
filter(version == as.Date("2020-07-01")) %>%
35-
na.omit() %>%
36-
select(-version) %>%
37-
as.data.frame()
38-
39-
expect_equal(df_as_of[1:4],df_filter)
40-
expect_equal(data.table::key(ea$DT), old_key)
27+
d <- as.Date("2020-06-01")
28+
29+
ea2 = tibble::tribble(
30+
~geo_value, ~time_value, ~version, ~cases,
31+
"ca", "2020-06-01", "2020-06-01", 1,
32+
"ca", "2020-06-01", "2020-06-02", 2,
33+
#
34+
"ca", "2020-06-02", "2020-06-02", 0,
35+
"ca", "2020-06-02", "2020-06-03", 1,
36+
"ca", "2020-06-02", "2020-06-04", 2,
37+
#
38+
"ca", "2020-06-03", "2020-06-03", 1,
39+
#
40+
"ca", "2020-06-04", "2020-06-04", 4,
41+
) %>%
42+
dplyr::mutate(dplyr::across(c(time_value, version), as.Date)) %>%
43+
as_epi_archive()
44+
45+
old_key = data.table::key(ea2$DT)
46+
47+
edf_as_of <- ea2 %>%
48+
epix_as_of(max_version = as.Date("2020-06-03"))
49+
50+
edf_expected <- as_epi_df(tibble(
51+
geo_value = "ca",
52+
time_value = d + 0:2,
53+
cases = c(2,1,1)
54+
), as_of = as.Date("2020-06-03"))
55+
56+
expect_equal(edf_as_of, edf_expected, ignore_attr=c(".internal.selfref", "sorted"))
57+
expect_equal(data.table::key(ea2$DT), old_key)
4158
})
4259

4360
test_that("quosure passing issue in epix_slide is resolved + other potential issues", {

0 commit comments

Comments
 (0)