Skip to content

Commit e417756

Browse files
committed
Relax typeof checks due to Date backing typeof inconsistencies
1 parent 26721fa commit e417756

File tree

5 files changed

+48
-57
lines changed

5 files changed

+48
-57
lines changed

R/archive.R

+17-24
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ validate_version_bound <- function(version_bound, x, na_ok = FALSE,
5252
class = "epiprocess__version_bound_mismatched_class"
5353
)
5454
}
55-
if (!identical(typeof(version_bound), typeof(x[["version"]]))) {
56-
cli_abort(
57-
"{version_bound_arg} must have the same `typeof` as x$version,
58-
which has a `typeof` of {typeof(x$version)}",
59-
class = "epiprocess__version_bound_mismatched_typeof"
60-
)
61-
}
6255
}
6356

6457
return(invisible(NULL))
@@ -207,23 +200,23 @@ next_after.Date <- function(x) x + 1L
207200
#' undergo tiny nonmeaningful revisions and the archive object with the
208201
#' default setting is too large.
209202
#' @param clobberable_versions_start Optional; `length`-1; either a value of the
210-
#' same `class` and `typeof` as `x$version`, or an `NA` of any `class` and
211-
#' `typeof`: specifically, either (a) the earliest version that could be
212-
#' subject to "clobbering" (being overwritten with different update data, but
213-
#' using the *same* version tag as the old update data), or (b) `NA`, to
214-
#' indicate that no versions are clobberable. There are a variety of reasons
215-
#' why versions could be clobberable under routine circumstances, such as (a)
216-
#' today's version of one/all of the columns being published after initially
217-
#' being filled with `NA` or LOCF, (b) a buggy version of today's data being
218-
#' published but then fixed and republished later in the day, or (c) data
219-
#' pipeline delays (e.g., publisher uploading, periodic scraping, database
220-
#' syncing, periodic fetching, etc.) that make events (a) or (b) reflected
221-
#' later in the day (or even on a different day) than expected; potential
222-
#' causes vary between different data pipelines. The default value is `NA`,
223-
#' which doesn't consider any versions to be clobberable. Another setting that
224-
#' may be appropriate for some pipelines is `max_version_with_row_in(x)`.
225-
#' @param versions_end Optional; length-1, same `class` and `typeof` as
226-
#' `x$version`: what is the last version we have observed? The default is
203+
#' same `class` as `x$version`, or an `NA` of any `class`: specifically,
204+
#' either (a) the earliest version that could be subject to "clobbering"
205+
#' (being overwritten with different update data, but using the *same* version
206+
#' tag as the old update data), or (b) `NA`, to indicate that no versions are
207+
#' clobberable. There are a variety of reasons why versions could be
208+
#' clobberable under routine circumstances, such as (a) today's version of
209+
#' one/all of the columns being published after initially being filled with
210+
#' `NA` or LOCF, (b) a buggy version of today's data being published but then
211+
#' fixed and republished later in the day, or (c) data pipeline delays (e.g.,
212+
#' publisher uploading, periodic scraping, database syncing, periodic
213+
#' fetching, etc.) that make events (a) or (b) reflected later in the day (or
214+
#' even on a different day) than expected; potential causes vary between
215+
#' different data pipelines. The default value is `NA`, which doesn't consider
216+
#' any versions to be clobberable. Another setting that may be appropriate for
217+
#' some pipelines is `max_version_with_row_in(x)`.
218+
#' @param versions_end Optional; length-1, same `class` as `x$version`: what is
219+
#' the last version we have observed? The default is
227220
#' `max_version_with_row_in(x)`, but values greater than this could also be
228221
#' valid, and would indicate that we observed additional versions of the data
229222
#' beyond `max(x$version)`, but they all contained empty updates. (The default

R/methods-epi_archive.R

+1-10
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,13 @@ epix_as_of <- function(x, version, min_time_value = -Inf, all_versions = FALSE,
8080
"`version` must have the same `class` vector as `epi_archive$DT$version`."
8181
)
8282
}
83-
if (!identical(typeof(version), typeof(x$DT$version))) {
84-
cli_abort(
85-
"`version` must have the same `typeof` as `epi_archive$DT$version`."
86-
)
87-
}
8883
assert_scalar(version, na.ok = FALSE)
8984
if (version > x$versions_end) {
9085
cli_abort("`version` must be at most `epi_archive$versions_end`.")
9186
}
9287
assert_scalar(min_time_value, na.ok = FALSE)
9388
min_time_value_inf <- is.infinite(min_time_value) && min_time_value < 0
94-
min_time_value_same_type <- typeof(min_time_value) == typeof(x$DT$time_value) &
95-
class(min_time_value) == class(x$DT$time_value)
89+
min_time_value_same_type <- identical(class(min_time_value), class(x$DT$time_value))
9690
if (!min_time_value_inf && !min_time_value_same_type) {
9791
cli_abort("`min_time_value` must be either -Inf or a time_value of the same type and
9892
class as `epi_archive$time_value`.")
@@ -941,9 +935,6 @@ epix_truncate_versions_after.epi_archive <- function(x, max_version) {
941935
if (!identical(class(max_version), class(x$DT$version))) {
942936
cli_abort("`max_version` must have the same `class` as `epi_archive$DT$version`.")
943937
}
944-
if (!identical(typeof(max_version), typeof(x$DT$version))) {
945-
cli_abort("`max_version` must have the same `typeof` as `epi_archive$DT$version`.")
946-
}
947938
assert_scalar(max_version, na.ok = FALSE)
948939
if (max_version > x$versions_end) {
949940
cli_abort("`max_version` must be at most `epi_archive$versions_end`.")

man/epi_archive.Rd

+17-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-archive-version-bounds.R

+11-4
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,21 @@ test_that("`validate_version_bound` validate and class checks together allow and
7171
# Bad:
7272
expect_error(validate_version_bound(3.5, x_int, TRUE, "vb"), regexp = "must have the same `class`")
7373
expect_error(validate_version_bound(.Machine$integer.max, x_dbl, TRUE, "vb"), regexp = "must have the same `class`")
74-
expect_error(validate_version_bound(
75-
`class<-`(list(2), "clazz"),
76-
tibble::tibble(version = `class<-`(5L, "clazz")), TRUE, "vb"
77-
), regexp = "must have the same `typeof`", class = "epiprocess__version_bound_mismatched_typeof")
7874
# Maybe questionable:
7975
expect_error(validate_version_bound(3, x_int, TRUE, "vb"))
8076
expect_error(validate_version_bound(3L, x_dbl, TRUE, "vb"))
77+
# Maybe questionable, but accept to relax things a bit, as this is happening
78+
# with Dates in some R(?) versions. Might need to turn some things into
79+
# vec_cast_common, but idea is just make Date stuff work for now:
80+
validate_version_bound(
81+
`class<-`(list(2), "clazz"),
82+
tibble::tibble(version = `class<-`(5L, "clazz")), TRUE, "vb"
83+
)
8184
# Good:
85+
validate_version_bound(
86+
`class<-`(2, "Date"),
87+
tibble::tibble(version = `class<-`(5L, "Date")), TRUE, "vb"
88+
)
8289
validate_version_bound(my_int, x_int, TRUE, "vb")
8390
validate_version_bound(my_dbl, x_dbl, TRUE, "vb")
8491
validate_version_bound(my_list, x_list, TRUE, "vb")

tests/testthat/test-time-utils.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ test_that("guess_period works", {
1717
# On Dates:
1818
daily_dates <- seq(as.Date("2020-01-01"), as.Date("2020-01-15"), by = "day")
1919
weekly_dates <- seq(as.Date("2020-01-01"), as.Date("2020-01-15"), by = "week")
20-
expect_identical(
20+
expect_equal(
2121
daily_dates[[1L]] + guess_period(daily_dates) * (seq_along(daily_dates) - 1L),
2222
daily_dates
2323
)
24-
expect_identical(
24+
expect_equal(
2525
weekly_dates[[1L]] + guess_period(weekly_dates) * (seq_along(weekly_dates) - 1L),
2626
weekly_dates
2727
)

0 commit comments

Comments
 (0)