-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[R] fix behaviour when converting timestamps with "" as tzone #30005
Comments
Weston Pace / @westonpace:
But that is exactly what was specified in R if I understand these statements correctly:
It sound to me like the user specified "session local timezone" so that is what I would expect to see in the time zone value in Arrow. |
Nicola Crane / @thisisnic: Option 3 would represent the most "natural" behaviour from that point of view. |
Carl Boettiger / @cboettig: |
Rok Mihevc / @rok: |
Dragoș Moldovan-Grünfeld / @dragosmg: Therefore, "1970-01-01" in "BST" will always be incorrect by a hour (BST is UTC +0100). I think we need to account for the offset too. Without correcting for the offset, we have the correct timezone, but the wrong time. See below. > a <- as.POSIXct("1970-01-01")
# the print method adds local tz when it is unspecified
> a
[1] "1970-01-01 BST"
> attributes(a)
$class
[1] "POSIXct" "POSIXt"
$tzone
[1] ""
> attr(a, "tzone") <- Sys.timezone()
> attributes(a)
$class
[1] "POSIXct" "POSIXt"
$tzone
[1] "Europe/London"
# print result looks the same as with an unspecified `tzone` attribute
> a
[1] "1970-01-01 BST"
# yet this is not enough for conversion to arrow, which makes no use of the tzone attribute and converts the equivalent UTC time, but with the desired timezone and, thus, introduces a "mistake".
> Array$create(a)
Array
<timestamp[us, tz=Europe/London]>
[
1969-12-31 23:00:00.000000
] |
Dragoș Moldovan-Grünfeld / @dragosmg: |
Joris Van den Bossche / @jorisvandenbossche: |
Dragoș Moldovan-Grünfeld / @dragosmg:
I think this is a 2 part problem:
|
Jonathan Keane / @jonkeane: |
Form the comments, we've decided to go with option 3:
Set the timezone to local time without changing the integer value fo the timestamp. We store whatever integer R passes to us (21600), with CST as the timezone set. Display is then "1970-01-01 00:00:00 CST"
This is surprising because we are asserting the local timezone when that is not specified in R.
============================================
POSIXct
in R can have timezones specified as""
which is typically interpreted as the session local timezone.This can lead to surprising results like:
See also: https://stackoverflow.com/questions/69670142/how-can-i-store-timezone-agnostic-dates-for-sharing-between-r-and-python-using-p/69678923#69678923
This runs counter to what timestamps without timezones are interpreted as in Arrow:
arrow/format/Schema.fbs
Lines 333 to 336 in 0366943
Critically in R, when
as.POSIXct("1970-01-01 00:00:00")
is run, the timestamp value is computed "as if" the timezone of the date-time values was the local timezone (and not UTC like the Arrow spec says).This can lead to some surprising results when converting these timezoneless timestamps from R to Arrow. Using
as.POSIXct("1970-01-01 00:00:00")
as an example, and presume US Central time. We have a few options:Warn when the timezone is "" or not set that the behavior might be surprising
We store whatever integer R passes to us (21600), with no timezone set. When someone sees this formatted, the times/dates will be what the time was at UTC ("1970-01-01 06:00:00")
Set the timezone to UTC without changing the integer value of the timestamp. We store whatever integer R passes to us (21600), with UTC as the timezone set. When someone sees this formatted, the times/dates will be in UTC ("1970-01-01 06:00:00 UTC") This might be surprising / counterintuitive because the timestamps will suddenly be different and will be based in UTC and not local time like people are expecting.
Set the timezone to local time without changing the integer value fo the timestamp. We store whatever integer R passes to us (21600), with CST as the timezone set. Display is then "1970-01-01 00:00:00 CST"
This is surprising because we are asserting the local timezone when that is not specified in R.
If someone is using a timestamp without tzone in R to represent a timezoneless timestamp, options 2 and 3 above violate that when it is put into Arrow. Whereas, if someone is using a timestamp that just so happens to be without a tzone but they assume it's in local time, option 1 leads to (very) surprising results
Reporter: Jonathan Keane / @jonkeane
Assignee: Dragoș Moldovan-Grünfeld / @dragosmg
Watchers: Rok Mihevc / @rok
Related issues:
PRs and other links:
Note: This issue was originally created as ARROW-14442. Please see the migration documentation for further details.
The text was updated successfully, but these errors were encountered: