tidyverts / tsibble

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

rbind() fails when appending tsibbles with yearmonth indices #256

Closed mbg-unsw closed 2 years ago

mbg-unsw commented 3 years ago

When I use rbind() to append two tsibbles with yearmonth indices, I get this error:

Error: `levels.yearmonth()` not supported.

e.g.

l1 <- tsibble(t=yearmonth("2020 Jan"), n=1, cat="a", index=t, key=cat)
l2 <- tsibble(t=yearmonth("2020 Jan"), n=1, cat="b", index=t, key=cat)
rbind(l1, l2)

The operation works as expected if the index is a plain date.

> sessionInfo()
R version 4.0.4 (2021-02-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux bullseye/sid

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

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

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

other attached packages:
[1] tsibble_0.9.4

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        lubridate_1.7.9.2 assertthat_0.2.1  crayon_1.4.0     
 [5] dplyr_1.0.4       R6_2.5.0          DBI_1.1.1         lifecycle_0.2.0  
 [9] magrittr_2.0.1    pillar_1.4.7      rlang_0.4.10      rstudioapi_0.13  
[13] vctrs_0.3.6       generics_0.1.0    ellipsis_0.3.1    glue_1.4.2       
[17] purrr_0.3.4       anytime_0.3.9     compiler_4.0.4    pkgconfig_2.0.3  
[21] tidyselect_1.1.0  tibble_3.0.6     
pollytatouin commented 2 years ago

Same problem on my end:

x1 <- tsibble::tourism
x2 <- tsibble::tourism

rbind(x1, x2)

Erreur : `levels.yearquarter()` not supported.
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=French_Canada.1252  LC_CTYPE=French_Canada.1252    LC_MONETARY=French_Canada.1252 LC_NUMERIC=C                  
[5] LC_TIME=French_Canada.1252    

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

other attached packages:
 [1] lubridate_1.7.10  concordance_2.0.0 ggplot2_3.3.5     feasts_0.2.2      vroom_1.5.4       dplyr_1.0.7       fable_0.3.1       fabletools_0.3.1 
 [9] tsibble_1.0.1     stringr_1.4.0    

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7           urca_1.3-0           progressr_0.8.0      pillar_1.6.2         compiler_4.1.0       tools_4.1.0          digest_0.6.27       
 [8] bit_4.0.4            lattice_0.20-44      nlme_3.1-152         lifecycle_1.0.0      tibble_3.1.3         gtable_0.3.0         anytime_0.3.9       
[15] pkgconfig_2.0.3      rlang_0.4.11         cli_3.0.1            parallel_4.1.0       withr_2.4.2          generics_0.1.0       vctrs_0.3.8         
[22] nnet_7.3-16          bit64_4.0.5          grid_4.1.0           tidyselect_1.1.1     data.table_1.14.0    glue_1.4.2           R6_2.5.0            
[29] fansi_0.5.0          distributional_0.2.2 farver_2.1.0         purrr_0.3.4          tidyr_1.1.3          tzdb_0.1.2           magrittr_2.0.1      
[36] scales_1.1.1         ellipsis_0.3.2       colorspace_2.0-2     numDeriv_2016.8-1.1  renv_0.14.0          utf8_1.2.2           stringi_1.7.3       
[43] munsell_0.5.0        crayon_1.4.1
earowang commented 2 years ago

thanks, fixed.

Cheers, Earo

On 18 Sep 2021, at 4:00, pollytatouin wrote:

Same problem on my end:

x1 <- tsibble::tourism
x2 <- tsibble::tourism

rbind(x1, x2)

Erreur : `levels.yearquarter()` not supported.
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=French_Canada.1252  LC_CTYPE=French_Canada.1252    
LC_MONETARY=French_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=French_Canada.1252

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

other attached packages:
 [1] lubridate_1.7.10  concordance_2.0.0 ggplot2_3.3.5     
feasts_0.2.2      vroom_1.5.4       dplyr_1.0.7       fable_0.3.1      
 fabletools_0.3.1
 [9] tsibble_1.0.1     stringr_1.4.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7           urca_1.3-0           progressr_0.8.0      
pillar_1.6.2         compiler_4.1.0       tools_4.1.0          
digest_0.6.27
 [8] bit_4.0.4            lattice_0.20-44      nlme_3.1-152         
lifecycle_1.0.0      tibble_3.1.3         gtable_0.3.0         
anytime_0.3.9
[15] pkgconfig_2.0.3      rlang_0.4.11         cli_3.0.1            
parallel_4.1.0       withr_2.4.2          generics_0.1.0       
vctrs_0.3.8
[22] nnet_7.3-16          bit64_4.0.5          grid_4.1.0           
tidyselect_1.1.1     data.table_1.14.0    glue_1.4.2           
R6_2.5.0
[29] fansi_0.5.0          distributional_0.2.2 farver_2.1.0         
purrr_0.3.4          tidyr_1.1.3          tzdb_0.1.2           
magrittr_2.0.1
[36] scales_1.1.1         ellipsis_0.3.2       colorspace_2.0-2     
numDeriv_2016.8-1.1  renv_0.14.0          utf8_1.2.2           
stringi_1.7.3
[43] munsell_0.5.0        crayon_1.4.1

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/tidyverts/tsibble/issues/256#issuecomment-921908197

Fuco1 commented 2 years ago

What was the reason behind reversing this patch? Somehow this worked for me for at least half a year and started failing after I updated to the current version. Interestingly it errors out somewhere deep inside ggplot. I don't know how it worked before, is it even possible it could've work? Maybe I was casting to tibble somewhere along the process :O

Anyway, why not support binding for tsibbles?

earowang commented 2 years ago

It's not much an issue if all inputs are tsibbles, but I don't think if a tsibble returned by rbind() is always valid. Anyway, the output of rbind() is often unpredictable, if inputs are various data classes. For example, the output can be a matrix. I have kept watching how {tibble} addressed the rbind() issue. And they eventually leave the issue as is ( https://github.com/tidyverse/tibble/pull/909#issuecomment-948033492)