tidyverts / fabletools

General fable features useful for extension packages
http://fabletools.tidyverts.org/
89 stars 31 forks source link

`stream()` errors with ARIMA uninformatively #373

Open Aariq opened 1 year ago

Aariq commented 1 year ago

I'd expect stream() to work similarly to refit() based on the documentation, but I get an error. Maybe it's just not supported yet, like ETS, and is supposed to fail faster with an informative error?

# Automatic ARIMA specification
library(tsibble)
#> 
#> Attaching package: 'tsibble'
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, union
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(fable)
#> Loading required package: fabletools
library(fabletools)
data_full <- tsibbledata::global_economy
data_train <- data_full |> filter(Year < 2015)
data_stream <- data_full |> filter(Year >= 2015)
mod <-
  data_train %>%
  filter(Country == "Australia") %>%
  model(ARIMA(log(GDP) ~ Population))
#> Warning in sqrt(diag(best$var.coef)): NaNs produced

refit(mod, data_full)
#> # A mable: 1 x 2
#> # Key:     Country [1]
#>   Country   `ARIMA(log(GDP) ~ Population)`
#>   <fct>                            <model>
#> 1 Australia    <LM w/ ARIMA(1,0,1) errors>
stream(mod, data_stream)
#> Error in `mutate()`:
#> ! Problem while computing `ARIMA(log(GDP) ~ Population) = (function
#>   (object, ...) ...`.
#> Caused by error in `if (self$stage %in% c("estimate", "refit")) ...`:
#> ! argument is of length zero

#> Backtrace:
#>      ▆
#>   1. ├─fabletools::stream(mod, data_stream)
#>   2. ├─fabletools:::stream.mdl_df(mod, data_stream)
#>   3. │ └─dplyr::mutate_at(object, vars(!!!mdls), stream, new_data, ...)
#>   4. │   ├─dplyr::mutate(.tbl, !!!funs)
#>   5. │   └─dplyr:::mutate.data.frame(.tbl, !!!funs)
#>   6. │     └─dplyr:::mutate_cols(.data, dplyr_quosures(...), caller_env = caller_env())
#>   7. │       ├─base::withCallingHandlers(...)
#>   8. │       └─mask$eval_all_mutate(quo)
#>   9. ├─fabletools (local) `<fn>`(`ARIMA(log(GDP) ~ Population)`, `<list>`)
#>  10. ├─fabletools:::stream.lst_mdl(`ARIMA(log(GDP) ~ Population)`, `<list>`)
#>  11. │ ├─fabletools:::add_class(map2(object, new_data, stream, ...), class(object))
#>  12. │ └─fabletools:::map2(object, new_data, stream, ...)
#>  13. │   └─base::mapply(.f, .x, .y, MoreArgs = list(...), SIMPLIFY = FALSE)
#>  14. │     ├─fabletools (local) `<fn>`(dots[[1L]][[1L]], dots[[2L]][[1L]])
#>  15. │     └─fabletools:::stream.mdl_ts(dots[[1L]][[1L]], dots[[2L]][[1L]])
#>  16. │       └─fabletools:::parse_model_rhs(object$model)
#>  17. │         └─fabletools:::map(...)
#>  18. │           └─base::lapply(.x, .f, ...)
#>  19. │             └─fabletools (local) FUN(X[[i]], ...)
#>  20. │               └─fabletools:::map(.x, eval_tidy, data = model$data, env = model$specials)
#>  21. │                 └─base::lapply(.x, .f, ...)
#>  22. │                   └─rlang (local) FUN(X[[i]], ...)
#>  23. ├─fable (local) pdq()
#>  24. └─base::.handleSimpleError(...)
#>  25.   └─dplyr (local) h(simpleError(msg, call))
#>  26.     └─rlang::abort(...)

Created on 2022-12-09 with reprex v2.0.2