Skip to content

Commit 57bafb0

Browse files
committed
fix: single data point per group epi_df now classified as day time type
1 parent 157a3c9 commit 57bafb0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

R/utils.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,13 @@ guess_time_type <- function(time_value, time_value_arg = rlang::caller_arg(time_
475475
if (inherits(time_value, "Date")) {
476476
unique_time_gaps <- as.numeric(diff(sort(unique(time_value))))
477477
# Gaps in a weekly date sequence will cause some diffs to be larger than 7
478-
# days, so check modulo 7 equality, rather than equality with 7.
479-
if (all(unique_time_gaps %% 7 == 0)) {
478+
# days, so check modulo 7 equality, rather than equality with 7. The length
479+
# check is there so that we don't classify epi_df with a single data point
480+
# per geo as "week".
481+
if (all(unique_time_gaps %% 7 == 0) && length(unique_time_gaps) > 0) {
480482
return("week")
481483
}
482-
if (all(unique_time_gaps >= 28)) {
484+
if (all(unique_time_gaps >= 28) && length(unique_time_gaps) > 0) {
483485
cli_abort(
484486
"Found a monthly or longer cadence in the time column `{time_value_arg}`.
485487
Consider using tsibble::yearmonth for monthly data and 'YYYY' integers for year data."

0 commit comments

Comments
 (0)