Commits


Romain Francois authored and Neal Richardson committed 22f3741026a
ARROW-7028: [R] Date roundtrip results in different R storage mode Although it's to some extent tolerated that Date vectors are backed by `integer` vectors, it's much more common that they are backed by numeric: ``` r .Internal(inspect(Sys.Date())) #> @7fb95b8178c0 14 REALSXP g0c1 [OBJ,ATT] (len=1, tl=0) 18425 #> ATTRIB: #> @7fb9586b1808 02 LISTSXP g0c0 [REF(1)] #> TAG: @7fb957004fd0 01 SYMSXP g0c0 [MARK,REF(25905),LCK,gp=0x6000] "class" (has value) #> @7fb95b817888 16 STRSXP g0c1 [REF(1)] (len=1, tl=0) #> @7fb9571c1530 09 CHARSXP g0c1 [MARK,REF(191),gp=0x61] [ASCII] [cached] "Date" .Internal(inspect(as.Date("1982-05-15"))) #> @7fb95c10eb58 14 REALSXP g0c1 [OBJ,ATT] (len=1, tl=0) 4517 #> ATTRIB: #> @7fb9587cbc48 02 LISTSXP g0c0 [REF(1)] #> TAG: @7fb957004fd0 01 SYMSXP g0c0 [MARK,REF(25948),LCK,gp=0x6000] "class" (has value) #> @7fb95c10eb20 16 STRSXP g0c1 [REF(1)] (len=1, tl=0) #> @7fb9571c1530 09 CHARSXP g0c1 [MARK,REF(192),gp=0x61] [ASCII] [cached] "Date" ``` <sup>Created on 2020-06-12 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup> So I've changed `Converter_Date32` to convert to a numeric vector: ``` r library(dplyr, warn.conflicts = FALSE) tmp = tempdir() dat = tibble(tag = as.Date("2018-01-01")) dat2 = tibble(tag2 = as.Date("2019-01-01")) arrow::write_parquet(dat, file.path(tmp, "dat.parquet")) dat = arrow::read_parquet(file.path(tmp, "dat.parquet")) typeof(dat$tag) #> [1] "double" typeof(dat2$tag2) #> [1] "double" bind_cols(dat, dat2) %>% mutate(comparison = if_else(TRUE, tag, tag2)) #> # A tibble: 1 x 3 #> tag tag2 comparison #> <date> <date> <date> #> 1 2018-01-01 2019-01-01 2018-01-01 ``` <sup>Created on 2020-06-12 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup> Note: `dplyr::if_else` is due a rewrite, probably in `funs::` that will be more `vctrs`-correct and perhaps would deal with the issue: ``` r library(dplyr, warn.conflicts = FALSE) today_dbl <- Sys.Date() today_int <- structure(as.integer(today_dbl), class = "Date") dplyr::if_else(TRUE, today_dbl, today_int) #> Error: `false` must be a `Date` object, not a `Date` object. ``` <sup>Created on 2020-06-12 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup> This might be a usecase for `vctrs::vec_cast_common()`. ping @lionel- @DavisVaughan: ``` r library(dplyr, warn.conflicts = FALSE) today_dbl <- Sys.Date() today_int <- structure(as.integer(today_dbl), class = "Date") .Internal(inspect( vctrs::vec_cast_common(today_dbl, today_int) )) #> @7ffe825f1688 19 VECSXP g0c2 [] (len=2, tl=0) #> @7ffe823aeaa0 14 REALSXP g0c1 [OBJ,REF(12),ATT] (len=1, tl=0) 18425 #> ATTRIB: #> @7ffe823b5408 02 LISTSXP g0c0 [REF(1)] #> TAG: @7ffe80804fd0 01 SYMSXP g1c0 [MARK,REF(33031),LCK,gp=0x6000] "class" (has value) #> @7ffe823aea68 16 STRSXP g0c1 [REF(65535)] (len=1, tl=0) #> @7ffe809c1530 09 CHARSXP g1c1 [MARK,REF(395),gp=0x61] [ASCII] [cached] "Date" #> @7ffe8265eb30 14 REALSXP g0c1 [OBJ,REF(1),ATT] (len=1, tl=0) 18425 #> ATTRIB: #> @7ffe82664938 02 LISTSXP g0c0 [REF(1)] #> TAG: @7ffe80804fd0 01 SYMSXP g1c0 [MARK,REF(33031),LCK,gp=0x6000] "class" (has value) #> @7ffe82d15d60 16 STRSXP g1c1 [MARK,REF(65535)] (len=1, tl=0) #> @7ffe809c1530 09 CHARSXP g1c1 [MARK,REF(395),gp=0x61] [ASCII] [cached] "Date" ``` <sup>Created on 2020-06-12 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup> Closes #7415 from romainfrancois/ARROW-7028 Lead-authored-by: Romain Francois <romain@rstudio.com> Co-authored-by: Neal Richardson <neal.p.richardson@gmail.com> Signed-off-by: Neal Richardson <neal.p.richardson@gmail.com>