Commits


Dewey Dunnington authored and Jonathan Keane committed e907a9f0786
ARROW-14227: [R] Implement lubridate is.* methods Implements `is.Date()`, `is.POSIXct()`, `is.timepoint()`, and `is.instant()` from the lubridate package. There is also `lubridate::is.POSIXt()` and `lubridate::is.POSIXlt()`...these are a bit more niche and I thought they might be confusing if implemented here. Another question I had while implementing this...can/should these return an `Expression$scalar()`? This isn't how the other `is.*()` functions are done but maybe this makes a difference? ``` r library(arrow, warn.conflicts = FALSE) library(lubridate, warn.conflicts = FALSE) library(dplyr, warn.conflicts = FALSE) test_date <- as.POSIXct("2017-01-01 00:00:11.3456789", tz = "Pacific/Marquesas") test_df <- tibble::tibble( datetime = c(test_date, NA) + 1, date = c(as.Date("2021-09-09"), NA) ) RecordBatch$create(test_df) %>% mutate(is.POSIXct(datetime), is.POSIXct(date)) %>% collect() #> # A tibble: 2 × 4 #> datetime date `is.POSIXct(datetime)` `is.POSIXct(date)` #> <dttm> <date> <lgl> <lgl> #> 1 2017-01-01 00:00:12 2021-09-09 TRUE FALSE #> 2 NA NA TRUE FALSE RecordBatch$create(test_df) %>% mutate(is.Date(datetime), is.Date(date)) %>% collect() #> # A tibble: 2 × 4 #> datetime date `is.Date(datetime)` `is.Date(date)` #> <dttm> <date> <lgl> <lgl> #> 1 2017-01-01 00:00:12 2021-09-09 FALSE TRUE #> 2 NA NA FALSE TRUE RecordBatch$create(test_df) %>% mutate(is.instant(datetime), is.instant(date)) %>% collect() #> # A tibble: 2 × 4 #> datetime date `is.instant(datetime)` `is.instant(date)` #> <dttm> <date> <lgl> <lgl> #> 1 2017-01-01 00:00:12 2021-09-09 TRUE TRUE #> 2 NA NA TRUE TRUE RecordBatch$create(test_df) %>% mutate(is.timepoint(datetime), is.timepoint(date)) %>% collect() #> # A tibble: 2 × 4 #> datetime date `is.timepoint(datetime)` `is.timepoint(date)` #> <dttm> <date> <lgl> <lgl> #> 1 2017-01-01 00:00:12 2021-09-09 TRUE TRUE #> 2 NA NA TRUE TRUE ``` <sup>Created on 2021-11-02 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup> Closes #11592 from paleolimbot/lubridate-is-methods Authored-by: Dewey Dunnington <dewey@fishandwhistle.net> Signed-off-by: Jonathan Keane <jkeane@gmail.com>