Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

as_forecast_quantile() renames the specified quantile level column in its input data to "quantile_level" (in place) #979

Open
dylanhmorris opened this issue Jan 4, 2025 · 1 comment

Comments

@dylanhmorris
Copy link

dylanhmorris commented Jan 4, 2025

This does not occur for the specified "forecast" and "observed" columns. This means that calling as_forecast_quantile() multiple times on the same input data.table can succeed the first time and fail subsequently.

Reprex

library(scoringutils)
library(data.table)

quantile_data <- data.table(my_quantile = c(0.25, 0.5),
                            forecast_value = c(1, 2),
                            observed_value = c(5, 5))

quantile_forecast <- quantile_data |>
    as_forecast_quantile(
        predicted = "forecast_value",
        observed = "observed_value",
        quantile_level = "my_quantile")

## the quantile_forecast output is as expected
quantile_forecast
#> Forecast type: quantile
#> Forecast unit:
#> 
#>    quantile_level predicted observed
#>             <num>     <num>    <num>
#> 1:           0.25         1        5
#> 2:           0.50         2        5

## the "my_quantile" column in the input quantile_data
## been renamed "quantile_level"; the "forecast_value"
## and "observed_value" columns retain
## their original names
quantile_data
#>    quantile_level forecast_value observed_value
#>             <num>          <num>          <num>
#> 1:           0.25              1              5
#> 2:           0.50              2              5

## this now raises an error, because the column name has changed
## from "my_quantile" to "quantile_level"
quantile_data |>
    as_forecast_quantile(
        predicted = "forecast_value",
        observed = "observed_value",
        quantile_level = "my_quantile")
#> Error in as_forecast_quantile.default(quantile_data, predicted = "forecast_value", : Assertion on 'quantile_level' failed: Must be a subset of {'quantile_level','forecast_value','observed_value'}, but has additional elements {'my_quantile'}.

Created on 2025-01-03 with reprex v2.1.1

Info

scoringutils version 2.0.0

Can provide full sessionInfo() output if needed.

@dylanhmorris
Copy link
Author

Potentially related to #972

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant