Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
ARROW-14442: [R] fix behaviour when converting timestamps with "" as tzone#12240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
eaf2fe9d7fee589f6e2baeba6e74ec5e3a32dd042a4cf3f4a3d9534ef38a2930238aa51a5fe712a2065a69df927135af60ea4ef87d9aa10a0bd4eabe1b11995466d392742681a1540dc05ebbb9463bce3388ff7e79460d16b270596a633b909f33825d455a91816861bf5b374f9552f4b0ffa4f68ccb248bac047e3f6a5b28d193f528647a5638c6b166c7086ca5a4e41b580fdaac2930415048d5434153343026fa510edd9d1d15f472103c071d07876c4835903fb2de58c8de31bf0ae5039a8fb19ce8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -72,7 +72,8 @@ std::shared_ptr<arrow::DataType> InferArrowTypeFromVector<INTSXP>(SEXP x) { | ||
| } else if (Rf_inherits(x, "POSIXct")) { | ||
| auto tzone_sexp = Rf_getAttrib(x, symbols::tzone); | ||
| if (Rf_isNull(tzone_sexp)) { | ||
dragosmg marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| return timestamp(TimeUnit::MICRO); | ||
| auto systzone_sexp = cpp11::package("base")["Sys.timezone"]; | ||
| return timestamp(TimeUnit::MICRO, CHAR(STRING_ELT(systzone_sexp(), 0))); | ||
| } else { | ||
| return timestamp(TimeUnit::MICRO, CHAR(STRING_ELT(tzone_sexp, 0))); | ||
| } | ||
| @@ -88,7 +89,8 @@ std::shared_ptr<arrow::DataType> InferArrowTypeFromVector<REALSXP>(SEXP x) { | ||
| if (Rf_inherits(x, "POSIXct")) { | ||
| auto tzone_sexp = Rf_getAttrib(x, symbols::tzone); | ||
| if (Rf_isNull(tzone_sexp)) { | ||
| return timestamp(TimeUnit::MICRO); | ||
| auto systzone_sexp = cpp11::package("base")["Sys.timezone"]; | ||
| return timestamp(TimeUnit::MICRO, CHAR(STRING_ELT(systzone_sexp(), 0))); | ||
| } else { | ||
| return timestamp(TimeUnit::MICRO, CHAR(STRING_ELT(tzone_sexp, 0))); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -260,18 +260,39 @@ 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 = ""), { | ||
dragosmg marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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", "")) | ||
| }) | ||
| # If there is a timezone set, we record that | ||
| withr::with_timezone("Pacific/Marquesas", { | ||
dragosmg marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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")) | ||
dragosmg marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| times_with_tz <- strptime( | ||
| "2019-02-03 12:34:56", | ||
| format = "%Y-%m-%d %H:%M:%S", | ||
| tz = "Asia/Katmandu") + 1:10 | ||
| expect_equal(attr(times, "tzone"), "Asia/Katmandu") | ||
| expect_array_roundtrip(times, timestamp("us", "Asia/Katmandu")) | ||
| }) | ||
| # and although the TZ is NULL in R, we set it to the Sys.timezone() | ||
| withr::with_timezone(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())) | ||
| }) | ||
| }) | ||
| test_that("Timezone handling in Arrow roundtrip (ARROW-3543)", { | ||
Uh oh!
There was an error while loading. Please reload this page.