Skip to content

Commit

Permalink
Merge pull request #223 from epiforecasts/fix-222
Browse files Browse the repository at this point in the history
get type from correct scope
  • Loading branch information
nikosbosse authored May 10, 2022
2 parents ae816a7 + b41f840 commit 2ff6141
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions R/utils_data_handling.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ sample_to_quantile <- function(data,
by <- setdiff(colnames(data), reserved_columns)

data <- data[, .(quantile = quantiles,
prediction = quantile(x = prediction, prob = quantiles,
type = type, na.rm = TRUE)),
prediction = quantile(x = prediction, prob = ..quantiles,
type = ..type, na.rm = TRUE)),
by = by]

return(data[])
Expand Down
25 changes: 18 additions & 7 deletions tests/testthat/test-utils_data_handling.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,30 @@ test_that("sample_to_quantiles works", {
)

quantile <- data.frame(
date = as.Date("2020-01-01") + 1:10,
date = rep(as.Date("2020-01-01") + 1:10, each = 2),
model = "model1",
true_value = 1:10,
prediction = c(2:11, 4:13),
quantile = rep(c(0.25, 0.75), each = 10)
true_value = rep(1:10, each = 2),
quantile = c(0.25, 0.75),
prediction = rep(2:11, each = 2) + c(0, 2)
)


quantile2 <- scoringutils::sample_to_quantile(samples, quantiles = c(0.25, 0.75))
quantile2 <- quantile2[order(model, quantile, date)]
data.table::setcolorder(quantile2, names(quantile))

expect_equal(quantile, as.data.frame(quantile2))

# Verify that `type` is correctly scoped in sample_to_quantile(), as it is
# also an argument.
# If it's not scoped well, the call to `sample_to_quantile()` will fail.
samples$type <- "test"

quantile3 <- sample_to_quantile(samples, quantiles = c(0.25, 0.75))
quantile3$type <- NULL

expect_identical(
quantile2,
quantile3
)

})


Expand Down

0 comments on commit 2ff6141

Please sign in to comment.