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

Fix future_frame() failure for single observations #142

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ezraporter
Copy link

Fixes #108

Allows tk_make_future_timeseries() to work with length one vectors which is the source of the future_frame() failure. Currently tk_make_future_timeseries() tries to infer the series frequency with the median time difference. For length one vectors this fix sets the frequency as one unit of the datatype (i.e. Date -> 1 day).

This also required an update to tk_get_timeseries_summary() which currently returns scale = "second" for all length 1 vectors.

Admittedly after implementing I'm not sure this is the best solution for future_frame() since it can cause some odd behavior if the frequency isn't really 1 unit of the datatype but you could only know it by looking across groups:

library(tidyverse)
library(timetk)

# weekly series
series <- tibble(
    group = c("A", "A", "B"),
    week = as.Date(c("2023-01-01", "2023-01-08", "2023-01-01"))
)

series |>
    group_by(group) |>
    future_frame(week, 4)

# group A comes out weekly but group B comes out daily
#> # A tibble: 8 × 2
#> # Groups:   group [2]
#> group week      
#> <chr> <date>    
#> 1 A     2023-01-15
#> 2 A     2023-01-22
#> 3 A     2023-01-29
#> 4 A     2023-02-05
#> 5 B     2023-01-02
#> 6 B     2023-01-03
#> 7 B     2023-01-04
#> 8 B     2023-01-05

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 this pull request may close these issues.

future_frame() fails on grouped data with one observation
1 participant