You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/02/07 15:34:47 UTC

[GitHub] [arrow] dragosmg opened a new pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

dragosmg opened a new pull request #12357:
URL: https://github.com/apache/arrow/pull/12357


   This PR should make the following snippets of code equivalent:
   ``` r
   df <- tibble::tibble(
     x = as.POSIXct(c("2022-02-07", "2022-03-04"), tz = "Pacific/Marquesas")  
   )
   
   df %>%
   mutate(timezone = tz(x))
   # A tibble: 2 × 2
     x                   timezone         
     <dttm>              <chr>            
   1 2022-02-07 00:00:00 Pacific/Marquesas
   2 2022-03-04 00:00:00 Pacific/Marquesas
   ```
   and
   ```r
   dr %>%
     record_batch() %>%
     mutate(timezone = tz(x) %>%
     collect()
   ```


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807296212



##########
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:
       What I was testing was the `warning` in `compare_dplyr_warning()` being promoted to `error` level. It is the message for this error we improved which otherwise would not have been visible.  




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807293850



##########
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:
       We could use `warning = TRUE` and `compare_dplyr_binding()` (and no longer use  `expect_snapshot()`), but we will no longer be testing the error messages (which we worked to improve only because they were visible).




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r810495937



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
+  register_binding("tz", function(x) {
+    if (!call_binding("is.POSIXct", x)) {
+      class <- type(x)$ToString()
+      abort(paste0("timezone extraction for objects of class `", class, "` not supported in Arrow"))

Review comment:
       ```suggestion
         abort(paste0("timezone extraction for objects of class `", type(x)$ToString(), "` not supported in Arrow"))
   ```




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1035531392


   `NA` will be "contagious" in arrow's `tz()` binding (as opposed to `lubridate::tz()` where they aren't):
   ``` r
   suppressMessages(library(arrow))
   suppressMessages(library(lubridate))
   suppressMessages(library(dplyr))
   
   df <- tibble(
     x = as.POSIXct(c("2022-02-07", NA), tz = "Pacific/Marquesas")
   )
   
   df %>% 
     record_batch() %>% 
     mutate(timezone_x = tz(x)) %>%
     collect()
   #> # A tibble: 2 × 2
   #>   x                   timezone_x
   #>   <dttm>              <chr>     
   #> 1 2022-02-07 00:00:00 UTC       
   #> 2 NA                  NA
    
   df %>% 
     mutate(timezone_x = tz(x))
   #> # A tibble: 2 × 2
   #>   x                   timezone_x       
   #>   <dttm>              <chr>            
   #> 1 2022-02-07 00:00:00 Pacific/Marquesas
   #> 2 NA                  Pacific/Marquesas
   
   
   
   ```
   
   <sup>Created on 2022-02-10 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r803478315



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")

Review comment:
       Moreover, `lubridate` will stop returning `"UTC"` (for some of the inputs it currently does) in the next update:
   > Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807296212



##########
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:
       What I was testing was the `warning` in `compare_dplyr_warning()` being promoted to `error` level. This is the error we improved which otherwise would not have been visible.  




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg edited a comment on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg edited a comment on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1035520619


   @jonkeane Thanks for your comments. On surfacing errors: for example, I used `abort()` when working out how to implement `format()` (https://github.com/dragosmg/arrow/blob/9c99c03d4bdd5b80dea8acf88a3949808662bd32/r/R/dplyr-funcs-type.R#L259), but that error never surfaces as it is intercepted by the `mutate()` "context" and data is pulled into R.  


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r803472886



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")

Review comment:
       Yep, my initial implementation did not return `"UTC"` for strings, etc. and FWIW I think that is the way to go. I then proceeded to implement it in a `lubridate`-like manner. That allows us to decide if we want to pair it back or not. My vote would go for return timezone when timezone exists, otherwise return `NA`. 




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r803478315



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")

Review comment:
       Moreover, `lubridate` will stop returning `"UTC"` (for some of the input it currently does) in the next update:
   > Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.

##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")

Review comment:
       Moreover, `lubridate` will stop returning `"UTC"` (for some of the inputs it currently does) in the next update:
   > Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807278646



##########
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:
       Not sure what to say:
   * `error` is an argument to `expect_snapshot()` and `warning` is to `compare_dplyr_equal()` 
   * I like the `expect_shapshot(..., error = TRUE)` a bit better since with the change we would lose some of the message cover:
   <img width="1199" alt="image" src="https://user-images.githubusercontent.com/13176361/154141559-aa613f56-e790-4ae2-af5b-488bd8ce43ee.png">
   




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r808332580



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,16 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
+  register_binding("tz", function(x) {
+    if (!call_binding("is.POSIXct", x)) {
+      if (inherits(x, "Expression")) {
+        class <- x$type()$ToString()
+      } else {
+        class <- type(x)
+      }
+      abort(paste0("timezone extraction for objects of class `", class, "` not supported in Arrow"))
+    }

Review comment:
       Oh also I shuffled around the `if` clause so that we error earlier in the body and then have a standard return if `x` gets through all the validation. This is functionally the same as what we had before, but I find matches the style of others a bit more (and IMO if we can avoid an early return in a function, it's good to)




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807292334



##########
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:
       TIL `...$ToString()`. I really like your suggestion. I thought of something like it and couldn't figure out how exactly to implement it. I guess the only limitation is that we will now surface the arrow data types instead of the matching R ones, which might cause confusion. 

##########
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:
       Done.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1035525325


   Worth noting that the current implementation diverges from `lubridate::tz()` as indicated in the conversation, namely it does not return `"UTC"` for strings, numerics or NAs.
   ``` r
   suppressMessages(library(lubridate))
   tz(NA)
   #> [1] "UTC"
   tz(2)
   #> Warning: tz(): Don't know how to compute timezone for object of class numeric;
   #> returning "UTC". This warning will become an error in the next major version of
   #> lubridate.
   #> [1] "UTC"
   tz(2.2)
   #> Warning: tz(): Don't know how to compute timezone for object of class numeric;
   #> returning "UTC". This warning will become an error in the next major version of
   #> lubridate.
   #> [1] "UTC"
   tz("string")
   #> [1] "UTC"
   ```
   
   <sup>Created on 2022-02-10 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1034722439


   To add to the conversation above. I think the right way to go is to extract timezone from the timestamp metadata and not look at each individual value. However, that could in a situation where a value is NA, but the column is a `timestamp` which will result in something like:
   
   ``` r
   suppressMessages(library(arrow))
   suppressMessages(library(dplyr))
   df <- tibble(
     x = as.POSIXct(c("2022-02-07", NA), tz = "Pacific/Marquesas")
   )
   
   df %>% 
     record_batch() %>% 
     mutate(timezone_x = tz(x)) %>% 
     collect()
   #> A tibble: 2 × 2
   #>   x                   timezone_x       
   #>   <dttm>              <chr>            
   #> 1 2022-02-07 00:00:00 Pacific/Marquesas
   #> 2 NA                  Pacific/Marquesas
   ```
   
   <sup>Created on 2022-02-10 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] github-actions[bot] commented on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1031601572






-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot edited a comment on pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1047826320


   Benchmark runs are scheduled for baseline = 5216c2bb3e4f9298230e2e38f29ff9889b5a152d and contender = 0eaafe8055441cd279e3657d3817fc325a52de72. 0eaafe8055441cd279e3657d3817fc325a52de72 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/236bcec12e894b22b6963fb19407f23a...200fd5d5cc2440b689eb0cdf2b57fe32/)
   [Finished :arrow_down:7.49% :arrow_up:5.58%] [test-mac-arm](https://conbench.ursa.dev/compare/runs/eed1fa51f67647669fe1f50d45cc958e...fddc024b544f4534b2621604fc58c0fa/)
   [Failed :arrow_down:1.81% :arrow_up:3.25%] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/5027a2ad5fb84e20bc66af9d0dd91a5b...072da77ffa054ffca65c7674b7dfbe0b/)
   [Finished :arrow_down:0.52% :arrow_up:0.0%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/6c829c5c6e8d4c9fad9a20d6756e030b...c8bd367bf6ba4b1891693586e63687c2/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r803535644



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")
+    } else {
+      return(x$type()$timezone())
+    }

Review comment:
       We could go back to my first variant, which was also the simplest:
   ```r
     register_binding("tz", function(x) {
         x$type()$timezone()
     })
   ```
   
   I can't figure out how to surface an error from `tz()` as it gets caught by the dplyr query and then the dplyr-equivalent expression still gets evaluated in R.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
jonkeane commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1035575913


   > Worth noting that the current implementation diverges from lubridate::tz() as indicated in the conversation, namely it does not return "UTC" for strings, numerics or NAs.
   
   I think this is totally fine. For at least the numerics, lubridate will soon be doing what we do. For the others (strings, and bare NAs) it doesn't look like they are going to deprecate them, but I don't think we need to also follow that. We should note that (at least in a comment in the code, or in our documentation for the bindings if there's a place to put it).
   
   >  NA will be "contagious" in arrow's tz() binding (as opposed to lubridate::tz() where they aren't):
   
   Yeah, we have a choice here. I'm actually a bit surprised that `lubridate::tz()` returns a timezone that's not `UTC` there given the docs(!). But actually that behavior seems right. A bare `NA` either shouldn't produce a timezone (or produce a default UTC for backwards compatibility). But if the NA has a timezone attribute, that should be used.
   
   Given that, we probably should take out the `is.na()` bit in our binding since that will match what `lubridate::tz()` here. I only suggested adding it if we were aiming to mimic the `lubridate::tz(NA)` behavior here (which I thought would be `UTC`, but turns out, it's not!). That has the added benefit that we don't do by-element comparison, which is nice!


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r804245782



##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -711,3 +711,37 @@ 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(z),
+          timezone_w = tz(w),
+          timezone_v = tz(v)
+        ) %>%
+        collect(),
+      df
+    ),
+    error = TRUE
+  )

Review comment:
       If we're testing our package's error messages (and those message or the behavior is different from dplyr's or lubridate's), we should do that outside of `compare_dplyr_binding()` since there's not really an output to compare to (one example: https://github.com/apache/arrow/blob/fa699117091917f0992225aff4e8d4c08910162a/r/tests/testthat/test-dplyr-funcs-string.R#L939-L948)
   
   or if the behavior was different, the results aren't exactly the same, example: https://github.com/apache/arrow/blob/fa699117091917f0992225aff4e8d4c08910162a/r/tests/testthat/test-dplyr-funcs-string.R#L236-L255




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r808346731



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,16 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
+  register_binding("tz", function(x) {
+    if (!call_binding("is.POSIXct", x)) {

Review comment:
       Oh, actually no — I'm totally wrong this is fine it's this that's the problem: 
   
   ```
   if (inherits(x, "Expression")) {
     class <- x$type()$ToString()
   } else {
     class <- type(x)
   }
   ```
   
   That  should actually be:
   
   ```
   if (inherits(x, "Expression")) {
     class <- x$type()$ToString()
   } else {
     class <- type(x)$ToString()
   }
   ```
   
   and realistically, that should not even need an `if` there and could be `type(x)$ToString()` if we added (or fixed) a `type` method for expressions (I get `Error: Unrecognized vector instance for type ENVSXP` when I try `type({Expression})`) But that doesn't have to happen here (though we should make a Jira for it!




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r808879527



##########
File path: r/tests/testthat/_snaps/dplyr-funcs-datetime.md
##########
@@ -0,0 +1,46 @@
+# extract tz
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_posixct_date = tz(posixct_date),
+      timezone_char_date = tz(char_date)) %>% collect(), df)
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: In tz(char_date), timezone extraction for objects of class `string` not supported in Arrow; pulling data into R
+      Class:   simpleWarning/warning/condition
+
+---
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_posixct_date = tz(posixct_date),
+      timezone_date_date = tz(date_date)) %>% collect(), df)
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: In tz(date_date), timezone extraction for objects of class `date32[day]` not supported in Arrow; pulling data into R
+      Class:   simpleWarning/warning/condition
+
+---
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_posixct_date = tz(posixct_date),
+      timezone_integer_date = tz(integer_date)) %>% collect(), df)
+    Warning <simpleWarning>
+      tz(): Don't know how to compute timezone for object of class integer; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class integer; returning "UTC". This warning will become an error in the next major version of lubridate.
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: In tz(integer_date), timezone extraction for objects of class `int32` not supported in Arrow; pulling data into R
+      Class:   simpleWarning/warning/condition
+
+---
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_posixct_date = tz(posixct_date),
+      timezone_double_date = tz(double_date)) %>% collect(), df)
+    Warning <simpleWarning>
+      tz(): Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: In tz(double_date), timezone extraction for objects of class `double` not supported in Arrow; pulling data into R
+      Class:   simpleWarning/warning/condition
+

Review comment:
       Happy with `expect_error()` by itself. 




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r808311898



##########
File path: r/tests/testthat/_snaps/dplyr-funcs-datetime.md
##########
@@ -0,0 +1,46 @@
+# extract tz
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_posixct_date = tz(posixct_date),
+      timezone_char_date = tz(char_date)) %>% collect(), df)
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: In tz(char_date), timezone extraction for objects of class `string` not supported in Arrow; pulling data into R
+      Class:   simpleWarning/warning/condition
+
+---
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_posixct_date = tz(posixct_date),
+      timezone_date_date = tz(date_date)) %>% collect(), df)
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: In tz(date_date), timezone extraction for objects of class `date32[day]` not supported in Arrow; pulling data into R
+      Class:   simpleWarning/warning/condition
+
+---
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_posixct_date = tz(posixct_date),
+      timezone_integer_date = tz(integer_date)) %>% collect(), df)
+    Warning <simpleWarning>
+      tz(): Don't know how to compute timezone for object of class integer; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class integer; returning "UTC". This warning will become an error in the next major version of lubridate.
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: In tz(integer_date), timezone extraction for objects of class `int32` not supported in Arrow; pulling data into R
+      Class:   simpleWarning/warning/condition
+
+---
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_posixct_date = tz(posixct_date),
+      timezone_double_date = tz(double_date)) %>% collect(), df)
+    Warning <simpleWarning>
+      tz(): Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: In tz(double_date), timezone extraction for objects of class `double` not supported in Arrow; pulling data into R
+      Class:   simpleWarning/warning/condition
+

Review comment:
       This file isn't needed using `expect_error()`. I'll let you decide if you prefer `expect_error()` like I sent (mostly out of convenience—it's what I had written out to test myself) or switch those `expect_error()`s into one `expect_snapshot()`

##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -711,3 +711,34 @@ test_that("am/pm mirror lubridate", {
   )
 
 })
+
+test_that("extract tz", {
+  df <- tibble(
+    posixct_date = as.POSIXct(c("2022-02-07", "2022-02-10"), tz = "Pacific/Marquesas"),
+  )
+
+  compare_dplyr_binding(
+    .input %>%
+      mutate(timezone_posixct_date = tz(posixct_date)) %>%
+      collect(),
+    df
+  )
+
+  expect_error(
+    call_binding("tz", Expression$scalar("2020-10-01")),
+    "timezone extraction for objects of class `string` not supported in Arrow"
+  )

Review comment:
       The bit that I think you were missing is `Expressoin$scalar(...)`. I found this by looking around to find similar calls in the tests.  Though there aren't any that are exactly the same, I found 
   
   https://github.com/apache/arrow/blob/3a8e409385c8455e6c80b867c5730965a501d113/r/tests/testthat/test-dplyr-funcs-datetime.R#L113-L120
   
   which lead me to look at `Expression`:
   
   https://github.com/apache/arrow/blob/3a8e409385c8455e6c80b867c5730965a501d113/r/R/expression.R#L188-L192

##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,16 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
+  register_binding("tz", function(x) {
+    if (!call_binding("is.POSIXct", x)) {

Review comment:
       This line isn't quite right, actually. We want to use something like `!is.POSIXct(x)` that will be compatible with either R objects or Arrow types. I know there is at least one place that we test if a thing is a timestamp like that. Could you see if you can find it + see what that uses to get this working?
   
   That _should_ allow one to then `arrow:::call_binding("tz", "2020-10-01")` and get an error directly.

##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,16 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
+  register_binding("tz", function(x) {
+    if (!call_binding("is.POSIXct", x)) {
+      if (inherits(x, "Expression")) {
+        class <- x$type()$ToString()
+      } else {
+        class <- type(x)
+      }
+      abort(paste0("timezone extraction for objects of class `", class, "` not supported in Arrow"))
+    }

Review comment:
       I had to make a few changes here to make sure that this works with both R objects and Arrow objects. I only discovered this in my own testing. We probably won't see many pure R objects here, but it's possible!
   
   We don't (AFAIK) have a unified way to get types that would work from R objects and Arrow objects, but it might be worth looking for one + making a jira if we don't have one already.
   
   

##########
File path: r/tests/testthat/test-dplyr-funcs-datetime.R
##########
@@ -711,3 +711,34 @@ test_that("am/pm mirror lubridate", {
   )
 
 })
+
+test_that("extract tz", {
+  df <- tibble(
+    posixct_date = as.POSIXct(c("2022-02-07", "2022-02-10"), tz = "Pacific/Marquesas"),

Review comment:
       I cleaned up the types that we aren't running through the dplyr pipeline here — we can add them in if/when we want to test that mechanism.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot edited a comment on pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1047826320


   Benchmark runs are scheduled for baseline = 5216c2bb3e4f9298230e2e38f29ff9889b5a152d and contender = 0eaafe8055441cd279e3657d3817fc325a52de72. 0eaafe8055441cd279e3657d3817fc325a52de72 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/236bcec12e894b22b6963fb19407f23a...200fd5d5cc2440b689eb0cdf2b57fe32/)
   [Scheduled] [test-mac-arm](https://conbench.ursa.dev/compare/runs/eed1fa51f67647669fe1f50d45cc958e...fddc024b544f4534b2621604fc58c0fa/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/5027a2ad5fb84e20bc66af9d0dd91a5b...072da77ffa054ffca65c7674b7dfbe0b/)
   [Scheduled] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/6c829c5c6e8d4c9fad9a20d6756e030b...c8bd367bf6ba4b1891693586e63687c2/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r804190644



##########
File path: r/tests/testthat/_snaps/dplyr-funcs-datetime.md
##########
@@ -0,0 +1,15 @@
+# extract tz
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_y = tz(x), timezone_z = tz(z),
+      timezone_w = tz(w), timezone_v = tz(v)) %>% collect(), df)
+    Warning <simpleWarning>
+      tz(): Don't know how to compute timezone for object of class integer; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class integer; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: Expression tz(z) not supported in Arrow; pulling data into R

Review comment:
       And, for when you're looking at this tomorrow, check out https://github.com/apache/arrow/blob/fa699117091917f0992225aff4e8d4c08910162a/r/R/dplyr-eval.R#L18-L60
   
   There are a few bits in there relevant to error messages + how to surface them to see what's going on as a developer + how you might craft an error message that will be percolated up




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg edited a comment on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg edited a comment on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1034722439


   To add to the conversation above. I think the right way to go is to extract timezone from the timestamp metadata and not look at each individual value. However, that could result in a situation where a value is NA, but the column is a `timestamp` which will result in something like:
   
   ``` r
   suppressMessages(library(arrow))
   suppressMessages(library(dplyr))
   df <- tibble(
     x = as.POSIXct(c("2022-02-07", NA), tz = "Pacific/Marquesas")
   )
   
   df %>% 
     record_batch() %>% 
     mutate(timezone_x = tz(x)) %>% 
     collect()
   #> A tibble: 2 × 2
   #>   x                   timezone_x       
   #>   <dttm>              <chr>            
   #> 1 2022-02-07 00:00:00 Pacific/Marquesas
   #> 2 NA                  Pacific/Marquesas
   ```
   
   <sup>Created on 2022-02-10 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r801986202



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")

Review comment:
       Hmm, I know that this is supported in lubridate, though it looks like even there it's only for backwards compatibility: 
   
   https://github.com/tidyverse/lubridate/blob/566590f51364e6c42251cc1721f37c314ddf7e5f/R/accessors-tz.r#L21-L22
   
   I wonder if we should add this and keep on maintaining compatibility with lubridate on a feature that they only have to maintain backwards compatibility is the right way to go... It is especially strange that something like `tz("foo")` or `tz(NA)` would return `UTC`, but even dates don't really line up to UTC (or rather: you can imagine conceptualizing a date with a timezone attached, so asserting that they are all UTC isn't quite right...)

##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")
+    } else {
+      return(x$type()$timezone())
+    }

Review comment:
       What happens if you call this binding on an integer or a float? 




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807295552



##########
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 would say that if we want to check the error messages, we should do that directly with `expect_error()` or `expect_snapshot()` wrapped around something like: 
   
   ```
   call_binding("tz", "this is a string!")
   ```
   
   Or we might need to turn that R string into an Arrow Scalar or Array...)




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807295552



##########
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 would say that if we want to check the error messages, we should do that directly with `expect_error()` or `expect_snapshot()` wrapped around something like: 
   
   ```
   call_binding("tz", "this is a string!")
   ```




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r808838002



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,16 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
+  register_binding("tz", function(x) {
+    if (!call_binding("is.POSIXct", x)) {

Review comment:
       https://issues.apache.org/jira/browse/ARROW-15712




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane closed pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane closed pull request #12357:
URL: https://github.com/apache/arrow/pull/12357


   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1041944527


   I pulled the branch locally to test and confirm I was giving the correct advice + something that will work. I ended up making a few changes and figured it would be quicker to push those directly. I'll comment inline about some of the changes too.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r803682442



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")

Review comment:
       Sounds good 👍 




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg edited a comment on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg edited a comment on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1031661846


   `lubridate::tz()` supports a bunch of types of inputs, for example character:
   ``` r
   suppressMessages(library(lubridate))
   suppressMessages(library(dplyr))
   tibble(
     a = "2022-02-07"
   ) %>% 
     mutate(timezone = tz(a))
   #> # A tibble: 1 × 2
   #>   a          timezone
   #>   <chr>      <chr>   
   #> 1 2022-02-07 UTC
   ```
   
   <sup>Created on 2022-02-07 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>
   
   Not sure we want to support all of them. Albeit, it defaults to `"UTC"` when extracting the timezone from a character.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r804164292



##########
File path: r/tests/testthat/_snaps/dplyr-funcs-datetime.md
##########
@@ -0,0 +1,15 @@
+# extract tz
+
+    Code
+      compare_dplyr_binding(.input %>% mutate(timezone_y = tz(x), timezone_z = tz(z),
+      timezone_w = tz(w), timezone_v = tz(v)) %>% collect(), df)
+    Warning <simpleWarning>
+      tz(): Don't know how to compute timezone for object of class integer; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class integer; returning "UTC". This warning will become an error in the next major version of lubridate.
+      tz(): Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.
+    Error <expectation_failure>
+      `via_batch <- rlang::eval_tidy(expr, rlang::new_data_mask(rlang::env(.input = record_batch(tbl))))` threw an unexpected warning.
+      Message: Expression tz(z) not supported in Arrow; pulling data into R

Review comment:
       > Thanks for your comments. On surfacing errors: for example, I used abort() when working out how to implement format() (https://github.com/dragosmg/arrow/blob/9c99c03d4bdd5b80dea8acf88a3949808662bd32/r/R/dplyr-funcs-type.R#L259), but that error never surfaces as it is intercepted by the mutate() "context" and data is pulled into R.
   
   Yup, that's expected, this message right here (at the front before `not supported in Arrow; pulling data into R` is the error message that I was asking about when I asked "What happens if you call this binding on an integer or a float?" 
   
   I believe this is ultimately coming from https://github.com/apache/arrow/blob/fa699117091917f0992225aff4e8d4c08910162a/r/R/dplyr-eval.R#L58 
   
   which might not be the best message. If we `abort()` when we get types we know won't work we might be able to give a bit more informative errors than `Expression tz(z) not supported`




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807286901



##########
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:
       OH, sorry I was off one level of the nesting. I might be misunderstanding the output that you're seeing there, but I interpret that as the snapshot is recording that there's no output (i.e. the expectation has passed). Which is what we expect with `warning = TRUE` 




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot commented on pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
ursabot commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1047826320


   Benchmark runs are scheduled for baseline = 5216c2bb3e4f9298230e2e38f29ff9889b5a152d and contender = 0eaafe8055441cd279e3657d3817fc325a52de72. 0eaafe8055441cd279e3657d3817fc325a52de72 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Scheduled] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/236bcec12e894b22b6963fb19407f23a...200fd5d5cc2440b689eb0cdf2b57fe32/)
   [Scheduled] [test-mac-arm](https://conbench.ursa.dev/compare/runs/eed1fa51f67647669fe1f50d45cc958e...fddc024b544f4534b2621604fc58c0fa/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/5027a2ad5fb84e20bc66af9d0dd91a5b...072da77ffa054ffca65c7674b7dfbe0b/)
   [Scheduled] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/6c829c5c6e8d4c9fad9a20d6756e030b...c8bd367bf6ba4b1891693586e63687c2/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot edited a comment on pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1047826320


   Benchmark runs are scheduled for baseline = 5216c2bb3e4f9298230e2e38f29ff9889b5a152d and contender = 0eaafe8055441cd279e3657d3817fc325a52de72. 0eaafe8055441cd279e3657d3817fc325a52de72 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/236bcec12e894b22b6963fb19407f23a...200fd5d5cc2440b689eb0cdf2b57fe32/)
   [Finished :arrow_down:7.49% :arrow_up:5.58%] [test-mac-arm](https://conbench.ursa.dev/compare/runs/eed1fa51f67647669fe1f50d45cc958e...fddc024b544f4534b2621604fc58c0fa/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/5027a2ad5fb84e20bc66af9d0dd91a5b...072da77ffa054ffca65c7674b7dfbe0b/)
   [Finished :arrow_down:0.52% :arrow_up:0.0%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/6c829c5c6e8d4c9fad9a20d6756e030b...c8bd367bf6ba4b1891693586e63687c2/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r803478315



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")

Review comment:
       Moreover, `lubridate` will stop returning `"UTC"` (for some of the input it currently does) in the next update:
   > Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807865735



##########
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 don't think something like `call_binding("tz", ...)` works because whatever we pass via the `...` needs to be an `Expression`. Which I think is the reason why `arrow::tz()` only works in a dplyr context, i.e. it doesn't work on standalone `Arrays`. That was why I was testing errors with dplyr pipelines.  




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
jonkeane commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1034947201


   I'm going to answer these two points below together, since they are similar. Both have tradeoffs, but what I do in circumstances like this is to look through our other bindings and see if I can find examples that do similar things.
   
   > To add to the conversation above. I think the right way to go is to extract timezone from the timestamp metadata and not look at each individual value. However, that could in a situation where a value is NA
   
   I agree that we should use the column metadata here (which is what it looks like you're doing), but then wrap it in an if_else detection if any elements are `NA` (one example is how we implemented `if_else()`(😂) https://github.com/apache/arrow/blob/af33dd1157eb8d7d9bfac25ebf61445b793b7943/r/R/dplyr-funcs-conditional.R#L51-L61 we also do similar with `is.finite()` and `is.infinite()` https://github.com/apache/arrow/blob/af33dd1157eb8d7d9bfac25ebf61445b793b7943/r/R/dplyr-funcs-type.R#L239-L249
   
   
   > I can't figure out how to surface an error from tz() as it gets caught by the dplyr query and then the dplyr-equivalent expression still gets evaluated in R.
   
   One example of having an error in a binding is https://github.com/apache/arrow/blob/af33dd1157eb8d7d9bfac25ebf61445b793b7943/r/R/dplyr-funcs-conditional.R#L86-L88 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1035520619


   On surfacing errors: for example, I used `abort()` when working out how to implement `format()` (https://github.com/dragosmg/arrow/blob/9c99c03d4bdd5b80dea8acf88a3949808662bd32/r/R/dplyr-funcs-type.R#L259), but that error never surfaces as it is intercepted by the `mutate()` "context" and data is pulled into R.  


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807271614



##########
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:
       Done




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807299424



##########
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:
       Done. 




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1046033487


   This is very very very close! I rebased off of the default branch since #12447 merged to get that fix. 
   
   I also updated the tests to mostly be the more simple R object in the `call_binding` but kept one that uses `Expression$create(...)` since `Expressions` are the type that will show up in the dplyr query.
   
   I did notice when testing locally (and I assume this'll pop up in the CI too), I think there might be a slight problem with #12447. It looks like `type({Expression object})` is returning the function for getting the type and not the Type object itself (hence everyone's favorite error message: `object of type closure is not subsetable`)
   
   I think that 
   
   https://github.com/apache/arrow/blob/f9f2c0827e1e605717d954c6899fe07b08f599cb/r/R/type.R#L81
   
   should actually be `type.Expression <- function(x) x$type()`
   
   It might be nice to add a test that asserts not just that `type(x)` and `x$type` are the same, but that `type(x)` produces the right Type object. So like this line:
   
   https://github.com/apache/arrow/blob/f9f2c0827e1e605717d954c6899fe07b08f599cb/r/tests/testthat/test-type.R#L238
   
   could also be tested with something like `expect_equal(type(x), int32())` which will make sure that what's coming out of `type(x)` there is definitely a type.
   
   It's a bit muddying this PR, but I'm happy for you to make those small adjustments here rather than a whole new Jira + commit chain + another wait to rebase after that's fixed.
   
   Other than that, this PR looks ready to go!


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r808875880



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,16 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
+  register_binding("tz", function(x) {
+    if (!call_binding("is.POSIXct", x)) {

Review comment:
       I have a PR (#12447) that adds a `type` method for `Expression` so we could rebase once that PR is merged.  




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] ursabot edited a comment on pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
ursabot edited a comment on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1047826320


   Benchmark runs are scheduled for baseline = 5216c2bb3e4f9298230e2e38f29ff9889b5a152d and contender = 0eaafe8055441cd279e3657d3817fc325a52de72. 0eaafe8055441cd279e3657d3817fc325a52de72 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Finished :arrow_down:0.0% :arrow_up:0.0%] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/236bcec12e894b22b6963fb19407f23a...200fd5d5cc2440b689eb0cdf2b57fe32/)
   [Scheduled] [test-mac-arm](https://conbench.ursa.dev/compare/runs/eed1fa51f67647669fe1f50d45cc958e...fddc024b544f4534b2621604fc58c0fa/)
   [Scheduled] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/5027a2ad5fb84e20bc66af9d0dd91a5b...072da77ffa054ffca65c7674b7dfbe0b/)
   [Finished :arrow_down:0.52% :arrow_up:0.0%] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/6c829c5c6e8d4c9fad9a20d6756e030b...c8bd367bf6ba4b1891693586e63687c2/)
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#issuecomment-1031661846


   `lubridate::tz()` supports a bunch of types of inputs, for example character:
   ``` r
   suppressMessages(library(lubridate))
   suppressMessages(library(dplyr))
   tibble(
     a = "2022-02-07"
   ) %>% 
     mutate(timezone = tz(a))
   #> # A tibble: 1 × 2
   #>   a          timezone
   #>   <chr>      <chr>   
   #> 1 2022-02-07 UTC
   ```
   
   <sup>Created on 2022-02-07 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup>


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r803478315



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")

Review comment:
       Moreover, `lubridate` will stop returning `"UTC"` in the next update:
   > Don't know how to compute timezone for object of class numeric; returning "UTC". This warning will become an error in the next major version of lubridate.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] dragosmg commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for lubridate::tz

Posted by GitBox <gi...@apache.org>.
dragosmg commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r803480656



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")
+    } else {
+      return(x$type()$timezone())
+    }

Review comment:
       It abandons ship and pulls data into R, when `lubridate` returns `"UTC"`.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow] jonkeane commented on a change in pull request #12357: ARROW-14817 [R] Implement bindings for `lubridate::tz()`

Posted by GitBox <gi...@apache.org>.
jonkeane commented on a change in pull request #12357:
URL: https://github.com/apache/arrow/pull/12357#discussion_r807304348



##########
File path: r/R/dplyr-funcs-datetime.R
##########
@@ -147,5 +147,12 @@ register_bindings_datetime <- function() {
   register_binding("pm", function(x) {
     !call_binding("am", x)
   })
-
+  register_binding("tz", function(x) {
+    if (call_binding("is.character", x) ||
+        call_binding("is.Date", x)) {
+      return("UTC")
+    } else {
+      return(x$type()$timezone())
+    }

Review comment:
       I actually think that's ok — the arrow types are a bit more confusing than the R types, _but_ they are more accurate for what the issue is.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org