From fd18c57b885c8de11545fd907098cb737bbffd56 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Fri, 3 May 2024 06:40:30 +0000 Subject: [PATCH] feat: add a new argument `strict` to `pl$Series()` --- R/series__series.R | 7 ++++++- man/pl_Series.Rd | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/R/series__series.R b/R/series__series.R index b26adba06..95850b49a 100644 --- a/R/series__series.R +++ b/R/series__series.R @@ -294,6 +294,10 @@ Series_struct = method_as_active_binding( #' If not `NULL`, that data type is used to [cast][Expr_cast] the Series created from the vector #' to a specific data type internally. #' @param ... Ignored. +#' @param strict A logical. If `TRUE` (default), throw an error if any value does not exactly match +#' the given data type by the `dtype` argument. If `FALSE`, values that do not match the data type +#' are cast to that data type or, if casting is not possible, set to `null` instead. +#' Passed to the `strict` argument of the [`$cast()`][Expr_cast] method internally. #' @param nan_to_null If `TRUE`, `NaN` values contained in the Series are replaced to `null`. #' Using the [`$fill_nan()`][Expr_fill_nan] method internally. #' @return [Series][Series_class] @@ -316,6 +320,7 @@ pl_Series = function( values = NULL, dtype = NULL, ..., + strict = TRUE, nan_to_null = FALSE) { uw = function(x) unwrap(x, "in pl$Series():") @@ -328,7 +333,7 @@ pl_Series = function( uw() if (!is.null(dtype)) { - out = result(out$cast(dtype)) |> + out = result(out$cast(dtype, strict)) |> uw() } diff --git a/man/pl_Series.Rd b/man/pl_Series.Rd index 09e899d3a..fee2b1514 100644 --- a/man/pl_Series.Rd +++ b/man/pl_Series.Rd @@ -5,7 +5,14 @@ \alias{Series} \title{Create new Series} \usage{ -pl_Series(name = NULL, values = NULL, dtype = NULL, ..., nan_to_null = FALSE) +pl_Series( + name = NULL, + values = NULL, + dtype = NULL, + ..., + strict = TRUE, + nan_to_null = FALSE +) } \arguments{ \item{name}{A character to use as the name of the Series, or \code{NULL} (default). @@ -20,6 +27,11 @@ to a specific data type internally.} \item{...}{Ignored.} +\item{strict}{A logical. If \code{TRUE} (default), throw an error if any value does not exactly match +the given data type by the \code{dtype} argument. If \code{FALSE}, values that do not match the data type +are cast to that data type or, if casting is not possible, set to \code{null} instead. +Passed to the \code{strict} argument of the \code{\link[=Expr_cast]{$cast()}} method internally.} + \item{nan_to_null}{If \code{TRUE}, \code{NaN} values contained in the Series are replaced to \code{null}. Using the \code{\link[=Expr_fill_nan]{$fill_nan()}} method internally.} }