Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support integer date and time classes from data.table #44174

Open
svraka opened this issue Sep 19, 2024 · 0 comments
Open

Support integer date and time classes from data.table #44174

svraka opened this issue Sep 19, 2024 · 0 comments

Comments

@svraka
Copy link

svraka commented Sep 19, 2024

Describe the enhancement requested

The data.table package introduces integer based date and time-of-day classes, IDate, and ITime. Besides lower storage/memory cost, they offer faster sorting and grouping. It would be useful if Arrow fully supported these classes.

As IDate inherits from Date, Arrow correctly converts it to date32 but there is no way to control which R type date32 is converted to.

library(arrow)
library(data.table)
id <- as.IDate(Sys.Date())
str(id)
#>  IDate[1:1], format: "2024-09-19"
chunked_array(id)
#> ChunkedArray
#> <date32[day]>
#> [
#>   [
#>     2024-09-19
#>   ]
#> ]
str(as.vector(chunked_array(id)))
#>  Date[1:1], format: "2024-09-19"

ITime can be correctly round-tripped, if I’m not mistaken this is because Arrow preserves metadata.

it <- as.ITime(Sys.time())
str(it)
#>  'ITime' int 17:27:28
chunked_array(it)
#> ChunkedArray
#> <character(0)>
#> [
#>   [
#>     62848
#>   ]
#> ]
str(as.vector(chunked_array(it)))
#>  'ITime' int 17:27:28

Although this works, converting to time32 would improve interoperability with other languages. data.table users would need some way to control how time32 is converted back is this case too.

Created on 2024-09-19 with reprex v2.1.1

Session info
sessioninfo::session_info()
#> ─ Session info ─────────────────────────────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14 ucrt)
#>  os       Windows 10 x64 (build 19045)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  Hungarian_Hungary.utf8
#>  ctype    Hungarian_Hungary.utf8
#>  tz       Europe/Budapest
#>  date     2024-09-19
#>  pandoc   3.2 @ C:/Users/SvrakaA/scoop/shims/ (via rmarkdown)
#> 
#> ─ Packages ─────────────────────────────────────────────────────────────────────────────────────────
#>  package     * version  date (UTC) lib source
#>  arrow       * 17.0.0.1 2024-08-21 [1] CRAN (R 4.4.1)
#>  assertthat    0.2.1    2019-03-21 [1] CRAN (R 4.4.0)
#>  backports     1.5.0    2024-05-23 [1] CRAN (R 4.4.0)
#>  base64url     1.4      2018-05-14 [1] CRAN (R 4.4.0)
#>  bit           4.0.5    2022-11-15 [1] CRAN (R 4.4.0)
#>  bit64         4.0.5    2020-08-30 [1] CRAN (R 4.4.0)
#>  callr         3.7.6    2024-03-25 [1] CRAN (R 4.4.0)
#>  cellranger    1.1.0    2016-07-27 [1] CRAN (R 4.4.0)
#>  cli           3.6.3    2024-06-21 [1] CRAN (R 4.4.1)
#>  clipr         0.8.0    2022-02-22 [1] CRAN (R 4.4.0)
#>  codetools     0.2-20   2024-03-31 [2] CRAN (R 4.4.1)
#>  colorspace    2.1-1    2024-07-26 [1] CRAN (R 4.4.1)
#>  data.table  * 1.16.0   2024-08-27 [1] CRAN (R 4.4.1)
#>  digest        0.6.37   2024-08-19 [1] CRAN (R 4.4.1)
#>  dplyr       * 1.1.4    2023-11-17 [1] CRAN (R 4.4.0)
#>  evaluate      1.0.0    2024-09-17 [1] CRAN (R 4.4.1)
#>  fansi         1.0.6    2023-12-08 [1] CRAN (R 4.4.0)
#>  fastmap       1.2.0    2024-05-15 [1] CRAN (R 4.4.0)
#>  forcats     * 1.0.0    2023-01-29 [1] CRAN (R 4.4.0)
#>  fs            1.6.4    2024-04-25 [1] CRAN (R 4.4.0)
#>  generics      0.1.3    2022-07-05 [1] CRAN (R 4.4.0)
#>  ggplot2     * 3.5.1    2024-04-23 [1] CRAN (R 4.4.0)
#>  glue          1.7.0    2024-01-09 [1] CRAN (R 4.4.0)
#>  gtable        0.3.5    2024-04-22 [1] CRAN (R 4.4.0)
#>  hms           1.1.3    2023-03-21 [1] CRAN (R 4.4.0)
#>  htmltools     0.5.8.1  2024-04-04 [1] CRAN (R 4.4.0)
#>  igraph        2.0.3    2024-03-13 [1] CRAN (R 4.4.0)
#>  knitr         1.48     2024-07-07 [1] CRAN (R 4.4.1)
#>  lifecycle     1.0.4    2023-11-07 [1] CRAN (R 4.4.0)
#>  lubridate   * 1.9.3    2023-09-27 [1] CRAN (R 4.4.0)
#>  magrittr      2.0.3    2022-03-30 [1] CRAN (R 4.4.0)
#>  munsell       0.5.1    2024-04-01 [1] CRAN (R 4.4.0)
#>  pillar        1.9.0    2023-03-22 [1] CRAN (R 4.4.0)
#>  pkgconfig     2.0.3    2019-09-22 [1] CRAN (R 4.4.0)
#>  processx      3.8.4    2024-03-16 [1] CRAN (R 4.4.0)
#>  ps            1.8.0    2024-09-12 [1] CRAN (R 4.4.1)
#>  purrr       * 1.0.2    2023-08-10 [1] CRAN (R 4.4.0)
#>  R6            2.5.1    2021-08-19 [1] CRAN (R 4.4.0)
#>  readr       * 2.1.5    2024-01-10 [1] CRAN (R 4.4.0)
#>  readxl      * 1.4.3    2023-07-06 [1] CRAN (R 4.4.0)
#>  reprex        2.1.1    2024-07-06 [1] CRAN (R 4.4.1)
#>  rlang         1.1.4    2024-06-04 [1] CRAN (R 4.4.0)
#>  rmarkdown     2.28     2024-08-17 [1] CRAN (R 4.4.1)
#>  rstudioapi    0.16.0   2024-03-24 [1] CRAN (R 4.4.0)
#>  scales        1.3.0    2023-11-28 [1] CRAN (R 4.4.0)
#>  secretbase    1.0.2    2024-09-09 [1] CRAN (R 4.4.1)
#>  sessioninfo   1.2.2    2021-12-06 [1] CRAN (R 4.4.0)
#>  stringi       1.8.4    2024-05-06 [1] CRAN (R 4.4.0)
#>  stringr     * 1.5.1    2023-11-14 [1] CRAN (R 4.4.0)
#>  targets     * 1.7.1    2024-06-20 [1] CRAN (R 4.4.1)
#>  tibble      * 3.2.1    2023-03-20 [1] CRAN (R 4.4.0)
#>  tidyr       * 1.3.1    2024-01-24 [1] CRAN (R 4.4.0)
#>  tidyselect    1.2.1    2024-03-11 [1] CRAN (R 4.4.0)
#>  tidyverse   * 2.0.0    2023-02-22 [1] CRAN (R 4.4.0)
#>  timechange    0.3.0    2024-01-18 [1] CRAN (R 4.4.0)
#>  tzdb          0.4.0    2023-05-12 [1] CRAN (R 4.4.0)
#>  utf8          1.2.4    2023-10-22 [1] CRAN (R 4.4.0)
#>  vctrs         0.6.5    2023-12-01 [1] CRAN (R 4.4.0)
#>  withr         3.0.1    2024-07-31 [1] CRAN (R 4.4.1)
#>  xfun          0.47     2024-08-17 [1] CRAN (R 4.4.1)
#>  yaml          2.3.10   2024-07-26 [1] CRAN (R 4.4.1)
#> 
#>  [1] C:/Users/SvrakaA/AppData/Local/R/win-library/4.4
#>  [2] C:/R/R-4.4.1/library
#> 
#> ────────────────────────────────────────────────────────────────────────────────────────────────────

Component(s)

R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant