Skip to content

Commit

Permalink
handle v3 samples when checking valid values
Browse files Browse the repository at this point in the history
  • Loading branch information
annakrystalli committed May 17, 2024
1 parent 5e94eb9 commit 2957a82
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/check_tbl_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ check_tbl_values <- function(tbl, round_id, file_path, hub_path) {
# This approach uses dplyr to identify tbl rows that don't have a complete match
# in accepted_vals.
accepted_vals$valid <- TRUE
if (hubUtils::is_v3_config(config_tasks)) {
out_type_ids <- tbl[["output_type_id"]]
tbl[tbl$output_type == "sample", "output_type_id"] <- NA
}

valid_tbl <- dplyr::left_join(
tbl, accepted_vals,
by = names(tbl)[names(tbl) != "value"]
Expand All @@ -36,6 +41,9 @@ check_tbl_values <- function(tbl, round_id, file_path, hub_path) {
if (length(error_summary$invalid_combs_idx) == 0L) {
error_tbl <- NULL
} else {
if (hubUtils::is_v3_config(config_tasks)) {
tbl[["output_type_id"]] <- out_type_ids
}
error_tbl <- tbl[
error_summary$invalid_combs_idx,
names(tbl) != "value"
Expand Down Expand Up @@ -125,7 +133,7 @@ coerce_num_output_type_ids <- function(tbl, file_path, hub_path) {
)

if (any(tbl[["output_type"]] %in% num_output_types) &&
inherits(tbl[["output_type_id"]], "character")) {
inherits(tbl[["output_type_id"]], "character")) {
type_coerce <- tbl[["output_type"]] %in% num_output_types
num_output_type_id <- suppressWarnings(
as.numeric(tbl$output_type_id[type_coerce])
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/_snaps/check_tbl_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@
Error:
! `tbl` contains invalid values/value combinations. Column `horizon` contains invalid value "11".

# check_tbl_values works with v3 spec samples

Code
check_tbl_values(tbl = tbl, round_id = round_id, file_path = file_path,
hub_path = hub_path)
Output
<message/check_success>
Message:
`tbl` contains valid values/value combinations.

---

Code
check_tbl_values(tbl = tbl, round_id = round_id, file_path = file_path,
hub_path = hub_path)
Output
<error/check_error>
Error:
! `tbl` contains invalid values/value combinations. Column `horizon` contains invalid values "11" and "12".

29 changes: 29 additions & 0 deletions tests/testthat/test-check_tbl_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,32 @@ test_that("check_tbl_values consistent across numeric & character output type id
exact = TRUE
)
})

test_that("check_tbl_values works with v3 spec samples", {
hub_path <- system.file("testhubs/samples", package = "hubValidations")
file_path <- "Flusight-baseline/2022-10-22-Flusight-baseline.csv"
round_id <- "2022-10-22"
tbl <- read_model_out_file(
file_path = file_path,
hub_path = hub_path,
coerce_types = "chr"
)
expect_snapshot(
check_tbl_values(
tbl = tbl,
round_id = round_id,
file_path = file_path,
hub_path = hub_path
)
)

tbl[head(which(tbl$output_type == "sample"), 2), "horizon"] <- c("11", "12")
expect_snapshot(
check_tbl_values(
tbl = tbl,
round_id = round_id,
file_path = file_path,
hub_path = hub_path
)
)
})

0 comments on commit 2957a82

Please sign in to comment.