From ba91d18258500b8f7db50d3e74a73234d72a3c05 Mon Sep 17 00:00:00 2001 From: nikosbosse Date: Wed, 3 Jan 2024 16:34:32 +0100 Subject: [PATCH] remove forecast_unit, forecast_type and warnings attribute in `validate_general()` --- NAMESPACE | 1 - R/available_forecasts.R | 2 +- R/score.R | 4 ++-- R/validate.R | 12 +++--------- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 35c1eb7c0..fed36e297 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/available_forecasts.R b/R/available_forecasts.R index db4d40c88..0ee143542 100644 --- a/R/available_forecasts.R +++ b/R/available_forecasts.R @@ -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)) { diff --git a/R/score.R b/R/score.R index 94d81fb16..8f85b3cf4 100644 --- a/R/score.R +++ b/R/score.R @@ -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 @@ -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 diff --git a/R/validate.R b/R/validate.R index faab1fbc6..02b4e62c6 100644 --- a/R/validate.R +++ b/R/validate.R @@ -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 @@ -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