Skip to content

Commit 52f747a

Browse files
committed
perform data validation on dates-as-strings
1 parent 86e1163 commit 52f747a

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

backfill_corrections/delphiBackfillCorrection/R/main.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,9 @@ main <- function(params,
309309
input_data <- lapply(
310310
files_list,
311311
function(file) {
312-
df <- read_data(file) %>%
312+
# refd_col and issued_col read in as strings
313+
read_data(file) %>%
313314
fips_to_geovalue()
314-
df[[refd_col]] <- as.Date(df[[refd_col]], "%Y-%m-%d")
315-
df[[issued_col]] <- as.Date(df[[issued_col]], "%Y-%m-%d")
316-
317-
return(df)
318315
}
319316
) %>%
320317
bind_rows()
@@ -336,6 +333,9 @@ main <- function(params,
336333
)
337334
input_data <- result[["df"]]
338335
}
336+
337+
input_data[[refd_col]] <- as.Date(input_data[[refd_col]], "%Y-%m-%d")
338+
input_data[[issued_col]] <- as.Date(input_data[[issued_col]], "%Y-%m-%d")
339339

340340
# Check available training days
341341
training_days_check(input_data[[issued_col]], params$training_days)

backfill_corrections/delphiBackfillCorrection/R/utils.R

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,11 @@ validity_checks <- function(df, value_type, num_col, denom_col, signal_suffixes,
156156
stop("No reference date column detected for the reference date!")
157157
}
158158

159-
if (!(inherits(df[[refd_col]], "Date"))) {
160-
stop("Reference date column must be of `Date` type")
161-
}
162-
163159
# issue_date and lag should exist in the dataset
164160
if ( !(lag_col %in% colnames(df)) || !(issued_col %in% colnames(df)) ) {
165161
stop("Issue date and lag fields must exist in the input data")
166162
}
167163

168-
if (!(inherits(df[[issued_col]], "Date"))) {
169-
stop("Issue date column must be of `Date` type")
170-
}
171-
172164
if ( any(is.na(df[[lag_col]])) || any(is.na(df[[issued_col]])) ||
173165
any(is.na(df[[refd_col]])) ) {
174166
stop("Issue date, lag, or reference date fields contain missing values")

0 commit comments

Comments
 (0)