tidyverts / tsibble

Tidy Temporal Data Frames and Tools
https://tsibble.tidyverts.org
GNU General Public License v3.0
527 stars 49 forks source link

Test suite fails with lubridate 1.9.0, tz = "US/Pacific" ? #292

Closed MichaelChirico closed 6 months ago

MichaelChirico commented 1 year ago

Our test suites for tsibble (1.1.3 from CRAN) started failing when we tried updating lubridate to 1.9.0 (from 1.8.0). It might be an internal issue on our side, but I am able to get the tests to pass when TZ=Etc/UTC, but the tests fail when TZ=US/Pacific. Here are the failures:

══ Failed tests ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
── Failure (test-filter-index.R:20): class: year* ──────────────────────────────
start_window(yrwk, x) (`actual`) not equal to yearweek(as.Date(c("2015-12-28", "2016-09-26", "2016-12-05"))) (`expected`).

`actual`:   "2015 W52" "2016 W38" "2016 W48"
`expected`: "2015 W53" "2016 W39" "2016 W49"
── Error (test-tsibble.R:390): as_tsibble.tbl_ts & as_tsibble.grouped_df ───────
Error in `validate_index(tbl, !!qindex)`: Column `mth` (index) must not contain `NA`.
Backtrace:
    ▆
 1. ├─testthat::expect_s3_class(...) at test-tsibble.R:390:2
 2. │ └─testthat::quasi_label(enquo(object), arg = "object")
 3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
 4. ├─tsibble::as_tsibble(tbl, key = group, index = mth)
 5. └─tsibble:::as_tsibble.grouped_df(tbl, key = group, index = mth)
 6.   └─tsibble::build_tsibble(...)
 7.     └─tsibble:::validate_index(tbl, !!qindex)
 8.       └─rlang::abort(...)
── Failure (test-yearmonth.R:7): input types for yearmonth() ───────────────────
yearmonth(dttm) (`actual`) not identical to `expected` (`expected`).

`actual`:   "2019 Sep" "2018 Jan"
`expected`: "2019 Aug" "2017 Dec"
── Failure (test-yearmonth.R:8): input types for yearmonth() ───────────────────
yearmonth(dates) (`actual`) not identical to `expected` (`expected`).

`actual`:   "2019 Sep" "2018 Jan"
`expected`: "2019 Aug" "2017 Dec"
── Failure (test-yearmonth.R:12): input types for yearmonth() ──────────────────
yearmonth(c(596, 576)) (`actual`) not identical to `expected` (`expected`).

`actual`:   "2019 Sep" "2018 Jan"
`expected`: "2019 Aug" "2017 Dec"
── Failure (test-yearmonth.R:16): vec_arith() for yearmonth() ──────────────────
yearmonth(x) + 1:2 (`actual`) not identical to yearmonth(c("2019 Oct", "2018 Mar")) (`expected`).

`actual`:   NA         NA        
`expected`: "2019 Sep" "2018 Feb"
── Failure (test-yearmonth.R:17): vec_arith() for yearmonth() ──────────────────
yearmonth(x) - 1 (`actual`) not identical to yearmonth(c("2019 Aug", "2017 Dec")) (`expected`).

`actual`:   "2019 Jul" NA        
`expected`: "2019 Jul" "2017 Nov"
── Failure (test-yearmonth.R:20): vec_arith() for yearmonth() ──────────────────
1 + yearmonth(x) (`actual`) not identical to yearmonth(x) + 1 (`expected`).

  `unclass(actual)`: NA 17532
`unclass(expected)`: NA 17562
── Failure (test-yearmonth.R:33): vec_cast() for yearmonth() ───────────────────
as.Date(yearmonth(x)) (`actual`) not identical to `dates` (`expected`).

`actual`:   "2019-08-31" "2017-12-31"
`expected`: "2019-09-01" "2018-01-01"
── Failure (test-yearmonth.R:34): vec_cast() for yearmonth() ───────────────────
as.character(yearmonth(x)) (`actual`) not identical to `x` (`expected`).

`actual`:   "2019 Aug" "2017 Dec"
`expected`: "2019 Sep" "2018 Jan"
── Failure (test-yearmonth.R:36): vec_cast() for yearmonth() ───────────────────
vec_cast(yearmonth(x), to = new_date()) (`actual`) not identical to `dates` (`expected`).

`actual`:   "2019-08-31" "2017-12-31"
`expected`: "2019-09-01" "2018-01-01"
── Failure (test-yearmonth.R:37): vec_cast() for yearmonth() ───────────────────
vec_data(as.POSIXct(yearmonth(x))) (`actual`) not identical to vec_data(dttm) (`expected`).

  `actual`: 1567209600 1514678400
`expected`: 1567296000 1514764800
── Failure (test-yearmonth.R:38): vec_cast() for yearmonth() ───────────────────
as.POSIXlt(yearmonth(x)) (`actual`) not identical to as.POSIXlt(dttm) (`expected`).

  `actual$mday`: 31 31
`expected$mday`:  1  1

  `actual$mon`: 7 11
`expected$mon`: 8  0

  `actual$year`: 119 117
`expected$year`: 119 118

  `actual$wday`: 6 0
`expected$wday`: 0 1

  `actual$yday`: 242 364
`expected$yday`: 243   0
── Failure (test-yearmonth.R:39): vec_cast() for yearmonth() ───────────────────
vec_data(vec_cast(yearmonth(x), to = new_datetime())) (`actual`) not identical to vec_data(dttm) (`expected`).

  `actual`: 1567209600 1514678400
`expected`: 1567296000 1514764800
── Failure (test-yearmonth.R:45): vec_c() for yearmonth() ──────────────────────
vec_c(dates, yearmonth(x)) (`actual`) not identical to rep(dates, times = 2) (`expected`).

`actual`:   "2019-09-01" "2018-01-01" "2019-08-31" "2017-12-31"
`expected`: "2019-09-01" "2018-01-01" "2019-09-01" "2018-01-01"
── Failure (test-yearmonth.R:46): vec_c() for yearmonth() ──────────────────────
vec_c(yearmonth(x), dates) (`actual`) not identical to rep(dates, times = 2) (`expected`).

`actual`:   "2019-08-31" "2017-12-31" "2019-09-01" "2018-01-01"
`expected`: "2019-09-01" "2018-01-01" "2019-09-01" "2018-01-01"
── Failure (test-yearmonth.R:47): vec_c() for yearmonth() ──────────────────────
vec_data(vec_c(dttm, yearmonth(x))) (`actual`) not identical to vec_data(rep(dttm, times = 2)) (`expected`).

  `actual`: 1567296000 1514764800 1567209600 1514678400
`expected`: 1567296000 1514764800 1567296000 1514764800
── Failure (test-yearmonth.R:50): vec_c() for yearmonth() ──────────────────────
vec_data(vec_c(yearmonth(x), dttm)) (`actual`) not identical to vec_data(rep(dttm, times = 2)) (`expected`).

  `actual`: 1567209600 1514678400 1567296000 1514764800
`expected`: 1567296000 1514764800 1567296000 1514764800

[ FAIL 18 | WARN 33 | SKIP 5 | PASS 715 ]

I guess #290 could be related

pgg1309 commented 1 year ago

All my scripts that are based on tsibble are failing because of this bug. I've tried replacing all text references (e.g. "2017 Sep") by make_yearmonth(2017,09) but it then fails in comparisons and in filter_index. For instance, replacing filter_index( "2017 Sep" ~ . ) by filter_index(make_yearmonth(2017,09) ~ .) does not work.

benzipperer commented 1 year ago

Hi, we also got bit by this bug. For example, yearmonth() seems to be off by one month:

> tsibble::yearmonth("2022m12")
<yearmonth[1]>
[1] "2022 Nov"
benzipperer commented 1 year ago

I confirmed as @MichaelChirico wrote the problem seems related to lubridate 1.9.0. For example:

> tsibble::yearmonth("2022m12")
<yearmonth[1]>
[1] "2022 Nov"
> sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9       lubridate_1.9.0  tsibble_1.1.3    fansi_1.0.3      assertthat_0.2.1 utf8_1.2.2       dplyr_1.0.10    
 [8] R6_2.5.1         DBI_1.1.3        lifecycle_1.0.3  magrittr_2.0.3   pillar_1.8.1     rlang_1.0.6      cli_3.4.1       
[15] rstudioapi_0.14  vctrs_0.5.1      generics_0.1.3   ellipsis_0.3.2   tools_4.2.2      glue_1.6.2       anytime_0.3.9   
[22] compiler_4.2.2   timechange_0.1.1 pkgconfig_2.0.3  tidyselect_1.2.0 tibble_3.1.8    

but then after clearing my session and devtools::install_version("lubridate", "1.8.0") we have

> tsibble::yearmonth("2022m12")
<yearmonth[1]>
[1] "2022 Dec"
> sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9       lubridate_1.8.0  tsibble_1.1.3    fansi_1.0.3      assertthat_0.2.1 utf8_1.2.2       dplyr_1.0.10    
 [8] R6_2.5.1         DBI_1.1.3        lifecycle_1.0.3  magrittr_2.0.3   pillar_1.8.1     rlang_1.0.6      cli_3.4.1       
[15] rstudioapi_0.14  vctrs_0.5.1      generics_0.1.3   ellipsis_0.3.2   tools_4.2.2      glue_1.6.2       anytime_0.3.9   
[22] compiler_4.2.2   pkgconfig_2.0.3  tidyselect_1.2.0 tibble_3.1.8    
earowang commented 6 months ago

looks like it gets fixed in upstream packages https://github.com/vspinu/timechange/pull/24 thanks for the help!