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

future_frame() fails on grouped data with one observation #108

Open
spsanderson opened this issue Jan 23, 2022 · 4 comments · May be fixed by #142
Open

future_frame() fails on grouped data with one observation #108

spsanderson opened this issue Jan 23, 2022 · 4 comments · May be fixed by #142

Comments

@spsanderson
Copy link

I have a script I run here: https://github.com/spsanderson/healthyverse_tsa

Today, there is only one record for my package TidyDensity. The record is below:

data_transformed_tbl %>% group_by(package) %>% filter(package == "TidyDensity")
# A tibble: 1 x 3
# Groups:   package [1]
  date       package     value_trans
  <date>     <chr>             <dbl>
1 2022-01-21 TidyDensity       0.179

When I try to use bind_rows to add a future_frame the process bombs out.

> data_transformed_tbl %>% 
  group_by(package) %>% 
  filter(package == "TidyDensity") %>% 
  bind_rows(future_frame(., .date_var = date, .length_out = horizon))

Error: Problem with `mutate()` column `nested.col`.
i `nested.col = purrr::map(...)`.
x error in evaluating the argument 'x' in selecting a method for function 'as_date': 'from' must be a finite number
i The error occurred in group 1: package = "TidyDensity".
Run `rlang::last_error()` to see where the error occurred.

Here is the rlang::last_error()

> rlang::last_error()
<error/dplyr:::mutate_error>
Problem with `mutate()` column `nested.col`.
i `nested.col = purrr::map(...)`.
x error in evaluating the argument 'x' in selecting a method for function 'as_date': 'from' must be a finite number
i The error occurred in group 1: package = "TidyDensity".
Backtrace:
  1. `%>%`(...)
 36. base::.handleSimpleError(...)
 37. dplyr:::h(simpleError(msg, call))
Run `rlang::last_trace()` to see the full context.

Here is the trance:

> rlang::last_trace()
<error/dplyr:::mutate_error>
Problem with `mutate()` column `nested.col`.
i `nested.col = purrr::map(...)`.
x error in evaluating the argument 'x' in selecting a method for function 'as_date': 'from' must be a finite number
i The error occurred in group 1: package = "TidyDensity".
Backtrace:
     x
  1. +-`%>%`(...)
  2. +-dplyr::bind_rows(., future_frame(., .date_var = date, .length_out = horizon))
  3. | \-rlang::list2(...)
  4. +-timetk::future_frame(., .date_var = date, .length_out = horizon)
  5. +-timetk:::future_frame.grouped_df(., .date_var = date, .length_out = horizon)
  6. | \-`%>%`(...)
  7. +-dplyr::group_by_at(., .vars = group_names)
  8. | \-dplyr:::manip_at(...)
  9. |   \-dplyr:::tbl_at_syms(.tbl, .vars, .include_group_vars = .include_group_vars)
 10. |     \-dplyr:::tbl_at_vars(tbl, vars, .include_group_vars = .include_group_vars)
 11. |       \-dplyr::tbl_vars(tbl)
 12. |         +-dplyr:::new_sel_vars(tbl_vars_dispatch(x), group_vars(x))
 13. |         | \-base::structure(...)
 14. |         \-dplyr:::tbl_vars_dispatch(x)
 15. +-tidyr::unnest(., cols = nested.col)
 16. +-dplyr::select(., -data)
 17. +-dplyr::mutate(...)
 18. +-dplyr:::mutate.data.frame(...)
 19. | \-dplyr:::mutate_cols(.data, ..., caller_env = caller_env())
 20. |   +-base::withCallingHandlers(...)
 21. |   \-mask$eval_all_mutate(quo)
 22. +-purrr::map(...)
 23. | \-timetk:::.f(.x[[i]], ...)
 24. |   \-timetk:::future_framer(...)
 25. |     +-timetk::tk_make_future_timeseries(...)
 26. |     \-timetk:::tk_make_future_timeseries.Date(...)
 27. |       \-`%>%`(...)
 28. +-lubridate::as_date(.)
 29. +-timetk:::tk_make_future_timeseries.yearmon(...)
 30. | \-timetk:::make_sequential_timeseries_regular_freq(...)
 31. |   +-base::seq(...)
 32. |   \-base::seq.default(...)
 33. |     \-base::stop("'from' must be a finite number")
 34. +-base::.handleSimpleError(...)
 35. | \-base:::h(simpleError(msg, call))
 36. \-base::.handleSimpleError(...)
 37.   \-dplyr:::h(simpleError(msg, call))
<error/simpleError>
error in evaluating the argument 'x' in selecting a method for function 'as_date': 'from' must be a finite number

Data is attached.

cran_logs.csv

@mdancho84
Copy link
Contributor

I'll take a look. I'm pretty sure it's because future frame expects a time delta which requires at least 2 time stamps.

Nevertheless I'm sure a fix can be made to help.

My time is very limited. I welcome any PRs if you'd like to try a fix.

@spsanderson
Copy link
Author

I'll try to fix

@mdancho84
Copy link
Contributor

Awesome. Just make a PR and let me know as you have questions.

@ezraporter ezraporter linked a pull request Mar 3, 2023 that will close this issue
@ezraporter
Copy link

I ran into this bug as well and came across this issue so I tried to implement a quick fix. As I mention in the PR I'm not sure my solution is the right one but may be better than erroring.

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

Successfully merging a pull request may close this issue.

3 participants