Skip to content

Commit

Permalink
refactor!: rename arguments of time zone methods [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Mar 19, 2024
1 parent 2b0dc7c commit 998229c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
30 changes: 7 additions & 23 deletions R/expr__datetime.R
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ ExprDT_convert_time_zone = function(tz) {
#' underlying timestamp. Use to correct a wrong time zone annotation. This will
#' change the corresponding global timepoint.
#'
#' @param tz NULL or string time zone from [base::OlsonNames()]
#' @param time_zone `NULL` or string time zone from [base::OlsonNames()]
#' @param ambiguous Determine how to deal with ambiguous datetimes:
#' * `"raise"` (default): throw an error
#' * `"earliest"`: use the earliest datetime
Expand All @@ -725,29 +725,13 @@ ExprDT_convert_time_zone = function(tz) {
#' @keywords ExprDT
#' @aliases (Expr)$dt$replace_time_zone
#' @examples
#' df_1 = pl$DataFrame(x = as.POSIXct("2009-08-07 00:00:01", tz = "America/New_York"))
#'
#' df_1$with_columns(
#' pl$col("x")$dt$replace_time_zone("UTC")$alias("utc"),
#' pl$col("x")$dt$replace_time_zone("Europe/Amsterdam")$alias("cest")
#' )
#'
#' # You can use ambiguous to deal with ambiguous datetimes
#' df_2 = pl$DataFrame(
#' x = seq(
#' as.POSIXct("2018-10-28 01:30", tz = "UTC"),
#' as.POSIXct("2018-10-28 02:30", tz = "UTC"),
#' by = "30 min"
#' )
#' )
#'
#' df_2$with_columns(
#' pl$col("x")$dt$replace_time_zone("Europe/Brussels", "earliest")$alias("earliest"),
#' pl$col("x")$dt$replace_time_zone("Europe/Brussels", "latest")$alias("latest"),
#' pl$col("x")$dt$replace_time_zone("Europe/Brussels", "null")$alias("null")
#' )
ExprDT_replace_time_zone = function(tz, ambiguous = "raise", non_existent = "raise") {
check_tz_to_result(tz) |>
ExprDT_replace_time_zone = function(
time_zone,
...,
ambiguous = "raise",
non_existent = "raise") {
check_tz_to_result(time_zone) |>
and_then(\(valid_tz) {
.pr$Expr$dt_replace_time_zone(self, valid_tz, ambiguous, non_existent)
}) |>
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,12 +1446,12 @@ impl RPolarsExpr {

pub fn dt_replace_time_zone(
&self,
tz: Nullable<String>,
time_zone: Nullable<String>,
ambiguous: Robj,
non_existent: Robj,
) -> RResult<Self> {
Ok(RPolarsExpr(self.0.clone().dt().replace_time_zone(
tz.into_option(),
time_zone.into_option(),
robj_to!(PLExpr, ambiguous)?,
robj_to!(NonExistent, non_existent)?,
)))
Expand Down

0 comments on commit 998229c

Please sign in to comment.