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/03/30 15:31:34 UTC

[GitHub] [arrow] jonkeane commented on a change in pull request #12240: ARROW-14442: [R] fix behaviour when converting timestamps with "" as tzone

jonkeane commented on a change in pull request #12240:
URL: https://github.com/apache/arrow/pull/12240#discussion_r838598898



##########
File path: r/tests/testthat/helper-skip.R
##########
@@ -78,3 +78,7 @@ process_is_running <- function(x) {
   cmd <- sprintf("ps aux | grep '%s' | grep -v grep", x)
   tryCatch(system(cmd, ignore.stdout = TRUE) == 0, error = function(e) FALSE)
 }
+
+on_windows <- function() {
+  ifelse(tolower(Sys.info()[["sysname"]]) == "windows", TRUE, FALSE)
+}

Review comment:
       Do we still need this helper?

##########
File path: r/tests/testthat/test-Array.R
##########
@@ -260,18 +260,28 @@ test_that("array supports POSIXct (ARROW-3340)", {
   expect_array_roundtrip(times2, timestamp("us", "US/Eastern"))
 })
 
-test_that("array supports POSIXct without timezone", {
-  # Make sure timezone is not set
+test_that("array uses local timezone for POSIXct without timezone", {
   withr::with_envvar(c(TZ = ""), {
     times <- strptime("2019-02-03 12:34:56", format = "%Y-%m-%d %H:%M:%S") + 1:10
-    expect_array_roundtrip(times, timestamp("us", ""))
+    expect_equal(attr(times, "tzone"), NULL)
+    expect_array_roundtrip(times, timestamp("us", Sys.timezone()))
 
     # Also test the INTSXP code path
     skip("Ingest_POSIXct only implemented for REALSXP")
     times_int <- as.integer(times)
     attributes(times_int) <- attributes(times)
     expect_array_roundtrip(times_int, timestamp("us", ""))
   })
+  withr::with_envvar(c(TZ = "Pacific/Marquesas"), {
+    times <- strptime("2019-02-03 12:34:56", format = "%Y-%m-%d %H:%M:%S") + 1:10
+    expect_equal(attr(times, "tzone"), "Pacific/Marquesas")
+    expect_array_roundtrip(times, timestamp("us", "Pacific/Marquesas"))
+  })
+  withr::with_envvar(c(TZ = NA), {
+    times <- strptime("2019-02-03 12:34:56", format = "%Y-%m-%d %H:%M:%S") + 1:10
+    expect_equal(attr(times, "tzone"), NULL)
+    expect_array_roundtrip(times, timestamp("us", Sys.timezone()))
+  })

Review comment:
       This might deserve a comment (the name of the test block is good!), but since this is towards the end, it might be good to say something like "and though the TZ is NULL in R, we set it to the Sys.timezone()"

##########
File path: r/tests/testthat/test-Array.R
##########
@@ -260,18 +260,28 @@ test_that("array supports POSIXct (ARROW-3340)", {
   expect_array_roundtrip(times2, timestamp("us", "US/Eastern"))
 })
 
-test_that("array supports POSIXct without timezone", {
-  # Make sure timezone is not set
+test_that("array uses local timezone for POSIXct without timezone", {
   withr::with_envvar(c(TZ = ""), {
     times <- strptime("2019-02-03 12:34:56", format = "%Y-%m-%d %H:%M:%S") + 1:10
-    expect_array_roundtrip(times, timestamp("us", ""))
+    expect_equal(attr(times, "tzone"), NULL)
+    expect_array_roundtrip(times, timestamp("us", Sys.timezone()))
 
     # Also test the INTSXP code path
     skip("Ingest_POSIXct only implemented for REALSXP")
     times_int <- as.integer(times)
     attributes(times_int) <- attributes(times)
     expect_array_roundtrip(times_int, timestamp("us", ""))
   })
+  withr::with_envvar(c(TZ = "Pacific/Marquesas"), {
+    times <- strptime("2019-02-03 12:34:56", format = "%Y-%m-%d %H:%M:%S") + 1:10
+    expect_equal(attr(times, "tzone"), "Pacific/Marquesas")
+    expect_array_roundtrip(times, timestamp("us", "Pacific/Marquesas"))
+  })
+  withr::with_envvar(c(TZ = NA), {
+    times <- strptime("2019-02-03 12:34:56", format = "%Y-%m-%d %H:%M:%S") + 1:10
+    expect_equal(attr(times, "tzone"), NULL)
+    expect_array_roundtrip(times, timestamp("us", Sys.timezone()))
+  })

Review comment:
       We might need to do something different here to confirm that these are actually having the effect we want:
   
   ```
   > withr::with_envvar(list("TZ" = "Europe/London"), {
   +   Sys.timezone()
   + })
   [1] "Europe/London"
   > 
   > withr::with_envvar(list("TZ" = "Europe/Paris"), {
   +   Sys.timezone()
   + })
   [1] "Europe/Paris"
   > 
   > withr::with_envvar(list("TZ" = ""), {
   +   Sys.timezone()
   + })
   [1] "America/Chicago"
   > 
   > withr::with_envvar(list("TZ" = "Europe/Paris"), {
   +   Sys.timezone()
   + })
   [1] "America/Chicago"
   ```
   
   We might want `withr::with_timezone` instead?




-- 
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