Skip to content

Unexpected error extracting intervals from dates given as POSIXct or datetime format #286

@cboettig

Description

@cboettig

Turning dates to datetimes results in an undefined interval, causing tsibble to fail to parse the index correctly.
I would expect that if index_valid(datetime) is true, I could use datetime as a valid index in as_tsibble().
Consider the following minimal reprex:

We define a sequence of dates as datetime data:

library(tsibble)
dates <- seq(as.Date("2017-01-01"), as.Date("2017-01-10"), by = 1)
datetime <- lubridate::as_datetime(dates)
index_valid(datetime)
#> [1] TRUE

Above, {tsibble} tells us YES this is still a valid index! But it cannot calculate the interval:

interval_pull(datetime)
#> <interval[1]>
#> [1] ?

and so we cannot actually use this index as a tsibble index:

as_tsibble(data.frame(time = datetime), index= time)
#> Error in `validate_interval()`:
#> ! Can't obtain the interval due to the mismatched index class.
#> ℹ Please see `vignette("FAQ")` for details.

Created on 2022-08-22 by the reprex package (v2.0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions