Skip to content

Commit

Permalink
remove forecast_unit, forecast_type and warnings attribute in `valida…
Browse files Browse the repository at this point in the history
…te_general()`
  • Loading branch information
nikosbosse committed Jan 3, 2024
1 parent a0f23ed commit ba91d18
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ importFrom(data.table,melt)
importFrom(data.table,nafill)
importFrom(data.table,rbindlist)
importFrom(data.table,setDT)
importFrom(data.table,setattr)
importFrom(data.table,setcolorder)
importFrom(data.table,setnames)
importFrom(ggdist,geom_lineribbon)
Expand Down
2 changes: 1 addition & 1 deletion R/available_forecasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ get_forecast_counts <- function(data,
collapse = c("quantile", "sample_id")) {

data <- as_forecast(data)
forecast_unit <- attr(data, "forecast_unit")
forecast_unit <- get_forecast_unit(data)
data <- na.omit(data)

if (is.null(by)) {
Expand Down
4 changes: 2 additions & 2 deletions R/score.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ score.forecast_point <- function(data, metrics = metrics_point, ...) {
score.forecast_sample <- function(data, metrics = metrics_sample, ...) {
data <- validate_forecast(data)
data <- na.omit(data)
forecast_unit <- attr(data, "forecast_unit")
forecast_unit <- get_forecast_unit(data)
metrics <- validate_metrics(metrics)

# transpose the forecasts that belong to the same forecast unit
Expand Down Expand Up @@ -158,7 +158,7 @@ score.forecast_sample <- function(data, metrics = metrics_sample, ...) {
score.forecast_quantile <- function(data, metrics = metrics_quantile, ...) {
data <- validate_forecast(data)
data <- na.omit(data)
forecast_unit <- attr(data, "forecast_unit")
forecast_unit <- get_forecast_unit(data)
metrics <- validate_metrics(metrics)

# transpose the forecasts that belong to the same forecast unit
Expand Down
12 changes: 3 additions & 9 deletions R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ validate_forecast.forecast_sample <- function(data, ...) {
#' @inheritParams get_forecast_counts
#' @return returns the input, with a few new attributes that hold additional
#' information, messages and warnings
#' @importFrom data.table ':=' is.data.table setattr
#' @importFrom data.table ':=' is.data.table
#' @importFrom checkmate assert_data_table
#' @export
#' @keywords internal_input_check
Expand All @@ -139,20 +139,14 @@ validate_general <- function(data) {
assert(check_data_columns(data))
data <- assure_model_column(data)

# assign forecast type and unit as an attribute and make sure there is no clash
forecast_type <- get_forecast_type(data)
setattr(data, "forecast_type", forecast_type)

forecast_unit <- get_forecast_unit(data, check_conflict = TRUE)
setattr(data, "forecast_unit", forecast_unit)

# check that there aren't any duplicated forecasts
forecast_unit <- get_forecast_unit(data, check_conflict = TRUE)
assert(check_duplicates(data, forecast_unit = forecast_unit))

# check that the number of forecasts per sample / quantile is the same
number_quantiles_samples <- check_number_per_forecast(data, forecast_unit)
if (!is.logical(number_quantiles_samples)) {
setattr(data, "warnings", number_quantiles_samples)
warning(number_quantiles_samples)
}

# check whether there are any NA values
Expand Down

0 comments on commit ba91d18

Please sign in to comment.