tidyverts / tsibble

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

`time_in()` should give error for numeric inputs when custom index class present #184

Closed mitchelloharawild closed 4 years ago

mitchelloharawild commented 4 years ago
library(tsibble)
tourism %>% filter_index(2000 ~ 2004)
#> # A tsibble: 0 x 5 [?]
#> # Key:       Region, State, Purpose [0]
#> # … with 5 variables: Quarter <qtr>, Region <chr>, State <chr>, Purpose <chr>,
#> #   Trips <dbl>

Created on 2020-04-24 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 3.6.2 (2019-12-12) #> os Ubuntu 18.04.4 LTS #> system x86_64, linux-gnu #> ui X11 #> language en_AU:en #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Melbourne #> date 2020-04-24 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> anytime 0.3.7 2020-01-20 [1] CRAN (R 3.6.1) #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1) #> backports 1.1.6 2020-04-05 [1] RSPM (R 3.6.3) #> callr 3.4.3 2020-03-28 [1] CRAN (R 3.6.2) #> cli 2.0.2 2020-02-28 [1] RSPM (R 3.6.2) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.1) #> devtools 2.2.2 2020-02-17 [1] RSPM (R 3.6.2) #> digest 0.6.25 2020-02-23 [1] RSPM (R 3.6.2) #> dplyr 0.8.99.9002 2020-03-29 [1] Github (tidyverse/dplyr@c7f2936) #> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1) #> fansi 0.4.1 2020-01-08 [1] RSPM (R 3.6.2) #> fs 1.3.2 2020-03-05 [1] RSPM (R 3.6.3) #> generics 0.0.2 2018-11-29 [1] CRAN (R 3.6.1) #> glue 1.3.2.9000 2020-03-29 [1] Github (tidyverse/glue@29eb0ff) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.1) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1) #> knitr 1.28 2020-02-06 [1] RSPM (R 3.6.2) #> lifecycle 0.2.0.9000 2020-03-19 [1] Github (r-lib/lifecycle@355dcba) #> lubridate 1.7.8 2020-04-06 [1] RSPM (R 3.6.3) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.1) #> pillar 1.4.3.9001 2020-03-29 [1] Github (r-lib/pillar@52b4503) #> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.1) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2) #> processx 3.4.2 2020-02-09 [1] RSPM (R 3.6.2) #> ps 1.3.2 2020-02-13 [1] RSPM (R 3.6.2) #> purrr 0.3.4 2020-04-17 [1] RSPM (R 3.6.3) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1) #> Rcpp 1.0.4.6 2020-04-09 [1] CRAN (R 3.6.2) #> remotes 2.1.1 2020-02-15 [1] RSPM (R 3.6.2) #> rlang 0.4.5.9000 2020-03-19 [1] Github (r-lib/rlang@a90b04b) #> rmarkdown 2.1 2020-01-20 [1] CRAN (R 3.6.1) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.1) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1) #> testthat 2.3.2 2020-03-02 [1] RSPM (R 3.6.3) #> tibble 3.0.0 2020-03-30 [1] CRAN (R 3.6.2) #> tidyselect 1.0.0 2020-01-27 [1] RSPM (R 3.6.2) #> tsibble * 0.8.9.9000 2020-04-07 [1] Github (tidyverts/tsibble@c5f1e90) #> usethis 1.5.1.9000 2020-01-31 [1] Github (r-lib/usethis@7d8b066) #> utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.1) #> vctrs 0.2.99.9010 2020-03-30 [1] Github (r-lib/vctrs@82920fe) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.1) #> xfun 0.12 2020-01-13 [1] RSPM (R 3.6.1) #> yaml 2.2.1 2020-02-01 [1] RSPM (R 3.6.2) #> #> [1] /home/mitchell/R/x86_64-pc-linux-gnu-library/3.6 #> [2] /opt/R/3.6.2/lib/R/library ```
earowang commented 4 years ago
library(tsibble)
time_in(pedestrian$Date_Time, 2015 ~ 2016)
#> Error: Must be character(s) for POSIXct, not double.
sum(time_in(tourism$Quarter, 2000 ~ 2004))
#> [1] 0

Created on 2020-04-24 by the reprex package (v0.3.0)

earowang commented 4 years ago

Oh these inputs are expected to be strings.

library(tsibble)
tourism %>% filter_index("2000" ~ "2004")
#> # A tsibble: 5,168 x 5 [1Q]
#> # Key:       Region, State, Purpose [304]
#>    Quarter Region   State           Purpose  Trips
#>      <qtr> <chr>    <chr>           <chr>    <dbl>
#>  1 2000 Q1 Adelaide South Australia Business  154.
#>  2 2000 Q2 Adelaide South Australia Business  169.
#>  3 2000 Q3 Adelaide South Australia Business  223.
#>  4 2000 Q4 Adelaide South Australia Business  241.
#>  5 2001 Q1 Adelaide South Australia Business  133.
#>  6 2001 Q2 Adelaide South Australia Business  178.
#>  7 2001 Q3 Adelaide South Australia Business  196.
#>  8 2001 Q4 Adelaide South Australia Business  101.
#>  9 2002 Q1 Adelaide South Australia Business  238.
#> 10 2002 Q2 Adelaide South Australia Business  151.
#> # … with 5,158 more rows

Created on 2020-04-24 by the reprex package (v0.3.0)

mitchelloharawild commented 4 years ago

I encountered this when updating fpp3, it was working with numerics before. Best mention it as a breaking change.