Skip to content

Commit

Permalink
rounding time() in time_to_date()
Browse files Browse the repository at this point in the history
closes #128
  • Loading branch information
earowang committed Jun 9, 2019
1 parent 2070a3b commit a4eb0b7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is a patch release.
* Fixed bugs for losing the "ordered" attribute when renaming a tsibble, introduced in v0.8.1 (#126).
* Fixed bug in `as.ts.tbl_ts()` for handling a tsibble of one row (#124).
* Fixed issue of `nest.tbl_ts()` for naming (#123).
* Fixed floating issues for duplicated indices in `as_tsibble.ts()` (#128).

# tsibble 0.8.1

Expand Down
2 changes: 1 addition & 1 deletion R/interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ time_to_date <- function(x, ...) {

time_to_date.ts <- function(x, tz = "UTC", ...) {
freq <- stats::frequency(x)
time_x <- as.numeric(stats::time(x))
time_x <- round(as.numeric(stats::time(x)), digits = 6) # floating
if (freq == 52) {
warn("Expected frequency of weekly data: 365.25 / 7 (approx 52.18), not 52.")
}
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-ts2tsibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ test_that("a mts", {
expect_identical(key_vars(tsbl2), character(0))
expect_identical(colnames(tsbl2), c("index", "Series 1", "Series 2"))
})

test_that("time floating #128", {
x <- ts(1:134, start = c(1960, 11), frequency = 12)
expect_true(anyDuplicated(as_tsibble(x)$index) == 0)
})

0 comments on commit a4eb0b7

Please sign in to comment.