diff --git a/R/expr__expr.R b/R/expr__expr.R index e655745f9..38f1fadb1 100644 --- a/R/expr__expr.R +++ b/R/expr__expr.R @@ -2249,15 +2249,17 @@ Expr_interpolate = function(method = "linear") { prepare_rolling_window_args = function( - window_size, # : int | str, - min_periods = NULL # : int | None = None, - ) { # ->tuple[str, int]: + window_size, + min_periods = NULL, + by, + closed) { if (is.numeric(window_size)) { if (is.null(min_periods)) min_periods = as.numeric(window_size) window_size = paste0(as.character(floor(window_size)), "i") } if (is.null(min_periods)) min_periods = 1 - list(window_size = window_size, min_periods = min_periods) + if (!is.null(by) && is.null(closed)) closed = "right" + list(window_size = window_size, min_periods = min_periods, closed = closed) } @@ -2291,10 +2293,11 @@ prepare_rolling_window_args = function( #' @param by If the `window_size` is temporal for instance `"5h"` or `"3s"`, you #' must set the column that will be used to determine the windows. This column #' must be of DataType Date or DateTime. -#' @param closed String, one of `"left"`, `"right"`, `"both"`, `"none"`. Defines -#' whether the temporal window interval is closed or not. -#' @param warn_if_unsorted Warn if data is not known to be sorted by `by` column (if passed). -#' Experimental. +#' @param closed Defines whether the temporal window interval is closed or not. +#' Only applicable if `by` is not `NULL` (in which case, its possible values are +#' `"left"`, `"right"` (default), `"both"`, `"none"`). +#' @param warn_if_unsorted Warn if data is not known to be sorted by `by` column +#' (if passed). #' #' @details #' If you want to compute multiple aggregation statistics over the same dynamic @@ -2310,12 +2313,12 @@ Expr_rolling_min = function( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE) { - wargs = prepare_rolling_window_args(window_size, min_periods) + wargs = prepare_rolling_window_args(window_size, min_periods, by, closed) .pr$Expr$rolling_min( self, wargs$window_size, weights, - wargs$min_periods, center, by, closed[1L], warn_if_unsorted + wargs$min_periods, center, by, wargs$closed, warn_if_unsorted ) |> unwrap("in $rolling_min():") } @@ -2336,12 +2339,12 @@ Expr_rolling_max = function( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE) { - wargs = prepare_rolling_window_args(window_size, min_periods) + wargs = prepare_rolling_window_args(window_size, min_periods, by, closed) .pr$Expr$rolling_max( self, wargs$window_size, weights, - wargs$min_periods, center, by, closed[1L], warn_if_unsorted + wargs$min_periods, center, by, wargs$closed, warn_if_unsorted ) |> unwrap("in $rolling_max()") } @@ -2362,12 +2365,12 @@ Expr_rolling_mean = function( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE) { - wargs = prepare_rolling_window_args(window_size, min_periods) + wargs = prepare_rolling_window_args(window_size, min_periods, by, closed) .pr$Expr$rolling_mean( self, wargs$window_size, weights, - wargs$min_periods, center, by, closed[1L], warn_if_unsorted + wargs$min_periods, center, by, wargs$closed, warn_if_unsorted ) |> unwrap("in $rolling_mean():") } @@ -2388,12 +2391,12 @@ Expr_rolling_sum = function( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE) { - wargs = prepare_rolling_window_args(window_size, min_periods) + wargs = prepare_rolling_window_args(window_size, min_periods, by, closed) .pr$Expr$rolling_sum( self, wargs$window_size, weights, - wargs$min_periods, center, by, closed[1L], warn_if_unsorted + wargs$min_periods, center, by, wargs$closed, warn_if_unsorted ) |> unwrap("in $rolling_sum():") } @@ -2416,12 +2419,12 @@ Expr_rolling_std = function( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE) { - wargs = prepare_rolling_window_args(window_size, min_periods) + wargs = prepare_rolling_window_args(window_size, min_periods, by, closed) .pr$Expr$rolling_std( self, wargs$window_size, weights, - wargs$min_periods, center, by, closed[1L], warn_if_unsorted + wargs$min_periods, center, by, wargs$closed, warn_if_unsorted ) |> unwrap("in $rolling_std(): ") } @@ -2443,12 +2446,12 @@ Expr_rolling_var = function( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE) { - wargs = prepare_rolling_window_args(window_size, min_periods) + wargs = prepare_rolling_window_args(window_size, min_periods, by, closed) .pr$Expr$rolling_var( self, wargs$window_size, weights, - wargs$min_periods, center, by, closed[1L], warn_if_unsorted + wargs$min_periods, center, by, wargs$closed, warn_if_unsorted ) |> unwrap("in $rolling_var():") } @@ -2470,12 +2473,12 @@ Expr_rolling_median = function( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE) { - wargs = prepare_rolling_window_args(window_size, min_periods) + wargs = prepare_rolling_window_args(window_size, min_periods, by, closed) .pr$Expr$rolling_median( self, wargs$window_size, weights, - wargs$min_periods, center, by, closed[1L], warn_if_unsorted + wargs$min_periods, center, by, wargs$closed, warn_if_unsorted ) |> unwrap("in $rolling_median():") } @@ -2501,12 +2504,12 @@ Expr_rolling_quantile = function( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE) { - wargs = prepare_rolling_window_args(window_size, min_periods) + wargs = prepare_rolling_window_args(window_size, min_periods, by, closed) .pr$Expr$rolling_quantile( self, quantile, interpolation, wargs$window_size, weights, - wargs$min_periods, center, by, closed[1L], warn_if_unsorted + wargs$min_periods, center, by, wargs$closed, warn_if_unsorted ) |> unwrap("in $rolling_quantile():") } diff --git a/man/Expr_rolling_max.Rd b/man/Expr_rolling_max.Rd index 2411f3684..4e59134d1 100644 --- a/man/Expr_rolling_max.Rd +++ b/man/Expr_rolling_max.Rd @@ -10,7 +10,7 @@ Expr_rolling_max( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE ) } @@ -45,11 +45,12 @@ before computing a result. If \code{NULL}, it will be set equal to window size.} must set the column that will be used to determine the windows. This column must be of DataType Date or DateTime.} -\item{closed}{String, one of \code{"left"}, \code{"right"}, \code{"both"}, \code{"none"}. Defines -whether the temporal window interval is closed or not.} +\item{closed}{Defines whether the temporal window interval is closed or not. +Only applicable if \code{by} is not \code{NULL} (in which case, its possible values are +\code{"left"}, \code{"right"} (default), \code{"both"}, \code{"none"}).} -\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column (if passed). -Experimental.} +\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column +(if passed).} } \value{ Expr diff --git a/man/Expr_rolling_mean.Rd b/man/Expr_rolling_mean.Rd index a9b3a317e..095beb6aa 100644 --- a/man/Expr_rolling_mean.Rd +++ b/man/Expr_rolling_mean.Rd @@ -10,7 +10,7 @@ Expr_rolling_mean( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE ) } @@ -45,11 +45,12 @@ before computing a result. If \code{NULL}, it will be set equal to window size.} must set the column that will be used to determine the windows. This column must be of DataType Date or DateTime.} -\item{closed}{String, one of \code{"left"}, \code{"right"}, \code{"both"}, \code{"none"}. Defines -whether the temporal window interval is closed or not.} +\item{closed}{Defines whether the temporal window interval is closed or not. +Only applicable if \code{by} is not \code{NULL} (in which case, its possible values are +\code{"left"}, \code{"right"} (default), \code{"both"}, \code{"none"}).} -\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column (if passed). -Experimental.} +\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column +(if passed).} } \value{ Expr diff --git a/man/Expr_rolling_median.Rd b/man/Expr_rolling_median.Rd index ea339b1c1..0e3274c46 100644 --- a/man/Expr_rolling_median.Rd +++ b/man/Expr_rolling_median.Rd @@ -10,7 +10,7 @@ Expr_rolling_median( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE ) } @@ -45,11 +45,12 @@ before computing a result. If \code{NULL}, it will be set equal to window size.} must set the column that will be used to determine the windows. This column must be of DataType Date or DateTime.} -\item{closed}{String, one of \code{"left"}, \code{"right"}, \code{"both"}, \code{"none"}. Defines -whether the temporal window interval is closed or not.} +\item{closed}{Defines whether the temporal window interval is closed or not. +Only applicable if \code{by} is not \code{NULL} (in which case, its possible values are +\code{"left"}, \code{"right"} (default), \code{"both"}, \code{"none"}).} -\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column (if passed). -Experimental.} +\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column +(if passed).} } \value{ Expr diff --git a/man/Expr_rolling_min.Rd b/man/Expr_rolling_min.Rd index 2ad4e7b66..f1487c6c5 100644 --- a/man/Expr_rolling_min.Rd +++ b/man/Expr_rolling_min.Rd @@ -10,7 +10,7 @@ Expr_rolling_min( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE ) } @@ -45,11 +45,12 @@ before computing a result. If \code{NULL}, it will be set equal to window size.} must set the column that will be used to determine the windows. This column must be of DataType Date or DateTime.} -\item{closed}{String, one of \code{"left"}, \code{"right"}, \code{"both"}, \code{"none"}. Defines -whether the temporal window interval is closed or not.} +\item{closed}{Defines whether the temporal window interval is closed or not. +Only applicable if \code{by} is not \code{NULL} (in which case, its possible values are +\code{"left"}, \code{"right"} (default), \code{"both"}, \code{"none"}).} -\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column (if passed). -Experimental.} +\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column +(if passed).} } \value{ Expr diff --git a/man/Expr_rolling_quantile.Rd b/man/Expr_rolling_quantile.Rd index 3441457a9..5408e1f77 100644 --- a/man/Expr_rolling_quantile.Rd +++ b/man/Expr_rolling_quantile.Rd @@ -12,7 +12,7 @@ Expr_rolling_quantile( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE ) } @@ -52,11 +52,12 @@ before computing a result. If \code{NULL}, it will be set equal to window size.} must set the column that will be used to determine the windows. This column must be of DataType Date or DateTime.} -\item{closed}{String, one of \code{"left"}, \code{"right"}, \code{"both"}, \code{"none"}. Defines -whether the temporal window interval is closed or not.} +\item{closed}{Defines whether the temporal window interval is closed or not. +Only applicable if \code{by} is not \code{NULL} (in which case, its possible values are +\code{"left"}, \code{"right"} (default), \code{"both"}, \code{"none"}).} -\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column (if passed). -Experimental.} +\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column +(if passed).} } \value{ Expr diff --git a/man/Expr_rolling_std.Rd b/man/Expr_rolling_std.Rd index 14c5ea2dc..4e1017248 100644 --- a/man/Expr_rolling_std.Rd +++ b/man/Expr_rolling_std.Rd @@ -10,7 +10,7 @@ Expr_rolling_std( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE ) } @@ -45,11 +45,12 @@ before computing a result. If \code{NULL}, it will be set equal to window size.} must set the column that will be used to determine the windows. This column must be of DataType Date or DateTime.} -\item{closed}{String, one of \code{"left"}, \code{"right"}, \code{"both"}, \code{"none"}. Defines -whether the temporal window interval is closed or not.} +\item{closed}{Defines whether the temporal window interval is closed or not. +Only applicable if \code{by} is not \code{NULL} (in which case, its possible values are +\code{"left"}, \code{"right"} (default), \code{"both"}, \code{"none"}).} -\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column (if passed). -Experimental.} +\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column +(if passed).} } \value{ Expr diff --git a/man/Expr_rolling_sum.Rd b/man/Expr_rolling_sum.Rd index 3ad13e6a8..4a10334a5 100644 --- a/man/Expr_rolling_sum.Rd +++ b/man/Expr_rolling_sum.Rd @@ -10,7 +10,7 @@ Expr_rolling_sum( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE ) } @@ -45,11 +45,12 @@ before computing a result. If \code{NULL}, it will be set equal to window size.} must set the column that will be used to determine the windows. This column must be of DataType Date or DateTime.} -\item{closed}{String, one of \code{"left"}, \code{"right"}, \code{"both"}, \code{"none"}. Defines -whether the temporal window interval is closed or not.} +\item{closed}{Defines whether the temporal window interval is closed or not. +Only applicable if \code{by} is not \code{NULL} (in which case, its possible values are +\code{"left"}, \code{"right"} (default), \code{"both"}, \code{"none"}).} -\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column (if passed). -Experimental.} +\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column +(if passed).} } \value{ Expr diff --git a/man/Expr_rolling_var.Rd b/man/Expr_rolling_var.Rd index de85e58f8..a9708faf5 100644 --- a/man/Expr_rolling_var.Rd +++ b/man/Expr_rolling_var.Rd @@ -10,7 +10,7 @@ Expr_rolling_var( min_periods = NULL, center = FALSE, by = NULL, - closed = c("left", "right", "both", "none"), + closed = NULL, warn_if_unsorted = TRUE ) } @@ -45,11 +45,12 @@ before computing a result. If \code{NULL}, it will be set equal to window size.} must set the column that will be used to determine the windows. This column must be of DataType Date or DateTime.} -\item{closed}{String, one of \code{"left"}, \code{"right"}, \code{"both"}, \code{"none"}. Defines -whether the temporal window interval is closed or not.} +\item{closed}{Defines whether the temporal window interval is closed or not. +Only applicable if \code{by} is not \code{NULL} (in which case, its possible values are +\code{"left"}, \code{"right"} (default), \code{"both"}, \code{"none"}).} -\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column (if passed). -Experimental.} +\item{warn_if_unsorted}{Warn if data is not known to be sorted by \code{by} column +(if passed).} } \value{ Expr