-
Notifications
You must be signed in to change notification settings - Fork 36
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
fix!: POSIXct without timezone and naive time handling #878
Conversation
a8914f3
to
ded6d13
Compare
Perhaps the POSIXct to Polars conversion also needs to be modified. Sys.setenv(TZ = "America/New_York")
datetime = as.POSIXct("2020-03-08 02:00:00")
datetime
#> [1] "2020-03-08 01:00:00 EST"
clock::as_naive_time(datetime)
#> <naive_time<second>[1]>
#> [1] "2020-03-08T01:00:00"
s = polars::as_polars_series(datetime)
s
#> polars Series: shape: (1,)
#> Series: '' [datetime[ms]]
#> [
#> 2020-03-08 06:00:00
#> ]
as.vector(s)
#> [1] "2020-03-08 01:00:00 EST" Created on 2024-03-02 with reprex v2.1.0 Perhaps it needs to behave like |
I think the following process is needed. polars::as_polars_series(datetime)$dt$replace_time_zone(
"UTC"
)$dt$convert_time_zone(
Sys.timezone()
)$dt$replace_time_zone(NULL) |
b3f6b4f
to
dea8554
Compare
Note that for the example in your first post, this is what I get with this PR: Sys.setenv(TZ = "America/New_York")
rdf = data.frame(
non_exsitent_time = as.POSIXct("2020-03-08 02:00:00"),
ambiguous_time = as.POSIXct("2020-11-01 01:00:00")
)
rdf
non_exsitent_time ambiguous_time
1 2020-03-08 2020-11-01 01:00:00
pldf = polars::as_polars_df(rdf)
pldf
shape: (1, 2)
┌─────────────────────┬─────────────────────┐
│ non_exsitent_time ┆ ambiguous_time │
│ --- ┆ --- │
│ datetime[ms] ┆ datetime[ms] │
╞═════════════════════╪═════════════════════╡
│ 2020-03-08 00:00:00 ┆ 2020-11-01 01:00:00 │
└─────────────────────┴─────────────────────┘ The column |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message following as.data.frame(pldf)
says Please use `ambiguous` to tell how it should be localized
but it's not clear to me where I should specify this arg
Interesting. Perhaps the environment changes the display of non-existent time? |
As I mentioned in the PR description, I would like to do this in a follow-up PR. It is also related to updates in other parts, for example, there is no option in |
How can I test that? The timezone is manually set so what else could change the display? |
It may not be possible to get consistent results on different platforms as this behavior varies from platform to platform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, just one last comment to clarify why this datetime doesn't exist
Co-authored-by: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com>
Thanks for the detailed review! |
Fix #875
The latest version (0.14.1):
This PR:
In the above example, an error occurs when converting Polars to R.
Perhaps something similar to the Int64 type conversion option should be added to the arguments and global options.