From 998229cc0f7382499de848a49a7f28412dfc70b2 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Tue, 19 Mar 2024 15:48:19 +0000 Subject: [PATCH] refactor!: rename arguments of time zone methods [skip ci] --- R/expr__datetime.R | 30 +++++++----------------------- src/rust/src/lazy/dsl.rs | 4 ++-- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/R/expr__datetime.R b/R/expr__datetime.R index e9695b03f..d10b21ead 100644 --- a/R/expr__datetime.R +++ b/R/expr__datetime.R @@ -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 @@ -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) }) |> diff --git a/src/rust/src/lazy/dsl.rs b/src/rust/src/lazy/dsl.rs index 95a51ccee..89e231f3b 100644 --- a/src/rust/src/lazy/dsl.rs +++ b/src/rust/src/lazy/dsl.rs @@ -1446,12 +1446,12 @@ impl RPolarsExpr { pub fn dt_replace_time_zone( &self, - tz: Nullable, + time_zone: Nullable, ambiguous: Robj, non_existent: Robj, ) -> RResult { 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)?, )))