tidyverts / tsibble

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

Unable to bind tsibble with `dplyr::bind_rows()` #178

Closed filipwastberg closed 4 years ago

filipwastberg commented 4 years ago

I'm having trouble binding tsibbles after updating both the tsibble and dplyr.

  1. The error Error: Theindexhas been dropped somehow. Please reconstruct tsibble. is generated when simply trying to bind two tsibbles.
    
    library(tsibble)
    library(tsibbledata)
    library(dplyr)
    #> 
    #> Attaching package: 'dplyr'
    #> The following objects are masked from 'package:stats':
    #> 
    #>     filter, lag
    #> The following objects are masked from 'package:base':
    #> 
    #>     intersect, setdiff, setequal, union

gafa_2014 <- gafa_stock %>% filter(Date < as.Date("2015-01-01"))

gafa_rest <- gafa_stock %>% filter(Date >= as.Date("2015-01-01"))

bind_rows(gafa_2014, gafa_rest)

> Error: The index has been dropped somehow. Please reconstruct tsibble.


<sup>Created on 2020-03-16 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>

2. Additionally, when creating a tsibble with a `yearmonth()` column, `bind_rows()`  seems to have trouble vectorizing the `yearmonth()` column and coerces it to numeric. Here I have coerced the tsibbles to tibbles.

``` r
gafa_2014_monthly <- gafa_stock %>% 
    filter(Date < as.Date("2015-01-01")) %>% 
    mutate(yearmonth = yearmonth(Date)) %>% 
    group_by(yearmonth) %>% 
    summarise(open = median(Open, na.rm = T)) %>% 
    as_tibble()

gafa_rest_monthly <- gafa_stock %>% 
    filter(Date >= as.Date("2015-01-01")) %>% 
    mutate(yearmonth = yearmonth(Date)) %>% 
    group_by(yearmonth) %>% 
    summarise(open = median(Open, na.rm = T)) %>% 
    as_tibble()

bind_rows(gafa_2014_monthly, gafa_rest_monthly)
#> Warning in bind_rows_(x, .id): Vectorizing 'yearmonth' elements may not
#> preserve their attributes

#> Warning in bind_rows_(x, .id): Vectorizing 'yearmonth' elements may not
#> preserve their attributes
#> # A tibble: 1,258 x 3
#>    yearmonth Date        open
#>        <dbl> <date>     <dbl>
#>  1     16071 2014-01-02  239.
#>  2     16071 2014-01-03  239.
#>  3     16071 2014-01-06  236.
#>  4     16071 2014-01-07  236.
#>  5     16071 2014-01-08  238.
#>  6     16071 2014-01-09  241.
#>  7     16071 2014-01-10  240.
#>  8     16071 2014-01-13  237.
#>  9     16071 2014-01-14  235.
#> 10     16071 2014-01-15  239.
#> # … with 1,248 more rows

Sessioninfo:

sessioninfo::session_info()
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.3 (2020-02-29)
 os       macOS Mojave 10.14.6        
 system   x86_64, darwin15.6.0        
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Europe/Stockholm            
 date     2020-03-16                  

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                                
 anytime       0.3.5      2019-07-28 [1] CRAN (R 3.6.0)                        
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)                        
 callr         3.3.1      2019-07-18 [1] CRAN (R 3.6.0)                        
 cli           2.0.2      2020-02-28 [1] CRAN (R 3.6.0)                        
 clipr         0.7.0      2019-07-23 [1] CRAN (R 3.6.0)                        
 crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)                        
 digest        0.6.20     2019-07-04 [1] CRAN (R 3.6.0)                        
 dplyr       * 0.8.5      2020-03-07 [1] CRAN (R 3.6.0)                        
 ellipsis      0.3.0      2019-09-20 [1] CRAN (R 3.6.0)                        
 evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)                        
 fansi         0.4.0      2018-10-05 [1] CRAN (R 3.6.0)                        
 fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)                        
 glue          1.3.1.9000 2019-07-01 [1] Github (tidyverse/glue@ea0edcb)       
 htmltools     0.4.0      2019-10-04 [1] CRAN (R 3.6.0)                        
 knitr         1.24       2019-08-08 [1] CRAN (R 3.6.0)                        
 lifecycle     0.1.0      2019-08-01 [1] CRAN (R 3.6.0)                        
 lubridate     1.7.4      2018-04-11 [1] CRAN (R 3.6.0)                        
 magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)                        
 packrat       0.5.0      2018-11-14 [1] CRAN (R 3.6.0)                        
 pillar        1.4.3      2019-12-20 [1] CRAN (R 3.6.0)                        
 pkgconfig     2.0.2      2018-08-16 [1] CRAN (R 3.6.0)                        
 processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.0)                        
 ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)                        
 purrr         0.3.3      2019-10-18 [1] CRAN (R 3.6.0)                        
 R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.0)                        
 Rcpp          1.0.2      2019-07-25 [1] CRAN (R 3.6.0)                        
 reprex        0.3.0      2019-05-16 [1] CRAN (R 3.6.0)                        
 rlang         0.4.5      2020-03-01 [1] CRAN (R 3.6.0)                        
 rmarkdown     1.14       2019-07-12 [1] CRAN (R 3.6.0)                        
 rstudioapi    0.11       2020-02-07 [1] CRAN (R 3.6.0)                        
 sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)                        
 stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)                        
 stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.0)                        
 tibble        2.1.3      2019-06-06 [1] CRAN (R 3.6.0)                        
 tidyselect    1.0.0      2020-01-27 [1] CRAN (R 3.6.0)                        
 tsibble     * 0.8.9.9000 2020-03-16 [1] Github (tidyverts/tsibble@c3fa67d)    
 tsibbledata * 0.1.0.9000 2020-03-16 [1] Github (tidyverts/tsibbledata@f666231)
 utf8          1.1.4      2018-05-24 [1] CRAN (R 3.6.0)                        
 vctrs         0.2.4      2020-03-10 [1] CRAN (R 3.6.0)                        
 whisker       0.3-2      2013-04-28 [1] CRAN (R 3.6.0)                        
 withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)                        
 xfun          0.8        2019-06-25 [1] CRAN (R 3.6.0)                        

[1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

Created on 2020-03-16 by the reprex package (v0.3.0)

earowang commented 4 years ago

Thanks. It will be fixed in the next release together with dplyr v1.0.0