jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807257233
##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -711,3 +711,71 @@ test_that("am/pm mirror lubridate", {
)
})
+
+test_that("extract tz", {
+ df <- tibble(
+ x = as.POSIXct(c("2022-02-07", "2022-02-10"), tz = "Pacific/Marquesas"),
+ #lubridate::tz() returns -for the time being - "UTC" for NAs, strings,
+ #dates and numerics
+ y = c("2022-02-07", NA),
+ z = as.Date(c("2022-02-07", NA)),
+ w = c(1L, 5L),
+ v = c(1.1, 2.47)
+ )
+
+ compare_dplyr_binding(
+ .input %>%
+ mutate(timezone_x = tz(x)) %>%
+ collect(),
+ df
+ )
+
+ expect_snapshot(
+ compare_dplyr_binding(
+ .input %>%
+ mutate(
+ timezone_y = tz(x),
+ timezone_z = tz(y)
+ ) %>%
+ collect(),
+ df
+ ),
+ error = TRUE
Review comment:
I think what you're looking for here (and below too) is:
```suggestion
warning = TRUE
```
That will ensure that the warning we're getting is the "not supported" kind,
and then compare the results after that.
https://github.com/apache/arrow/blob/96785665eff453aa4e5fc87a8ee5d047b9526869/r/tests/testthat/helper-expectation.R#L81-L85
`error = TRUE` is being passed via `...` to `expect_equal()` which also has
`...` which ends up being silently ignored.
##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,15 @@ register_bindings_datetime <- function() {
register_binding("pm", function(x) {
!call_binding("am", x)
})
-
+ register_binding("tz", function(x) {
+ if (call_binding("is.Date", x)) {
+ abort("timezone extraction for objects of class `date` not supported in
Arrow")
+ } else if (call_binding("is.numeric", x)) {
+ abort("timezone extraction for objects of class `numeric` not supported
in Arrow")
+ } else if (call_binding("is.character", x)) {
+ abort("timezone extraction for objects of class `character` not
supported in Arrow")
+ } else {
+ return(x$type()$timezone())
+ }
Review comment:
I wonder if it would be better to do this in the opposite way and check
that `x$type()` is a timestamp, and if it's not do something like:
```
abort(paste0("timezone extraction for objects of class `",
x$type$ToString(),"` not supported in Arrow"))
```
Which will guard against needing to add new types to this if/else if we add
new ones.
##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -711,3 +711,71 @@ test_that("am/pm mirror lubridate", {
)
})
+
+test_that("extract tz", {
+ df <- tibble(
+ x = as.POSIXct(c("2022-02-07", "2022-02-10"), tz = "Pacific/Marquesas"),
+ #lubridate::tz() returns -for the time being - "UTC" for NAs, strings,
+ #dates and numerics
Review comment:
```suggestion
# lubridate::tz() returns - for the time being - "UTC" for NAs, strings,
# dates and numerics
```
Super minor nit
##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -711,3 +711,71 @@ test_that("am/pm mirror lubridate", {
)
})
+
+test_that("extract tz", {
+ df <- tibble(
+ x = as.POSIXct(c("2022-02-07", "2022-02-10"), tz = "Pacific/Marquesas"),
+ #lubridate::tz() returns -for the time being - "UTC" for NAs, strings,
+ #dates and numerics
+ y = c("2022-02-07", NA),
+ z = as.Date(c("2022-02-07", NA)),
+ w = c(1L, 5L),
+ v = c(1.1, 2.47)
Review comment:
Would it be possible to name these columns with their types so it's
easier to reason about them down below and in their error messages?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]