diff --git a/R/extendr-wrappers.R b/R/extendr-wrappers.R index 90723eab9..718e1e4fd 100644 --- a/R/extendr-wrappers.R +++ b/R/extendr-wrappers.R @@ -1324,6 +1324,8 @@ RPolarsSeries$set_sorted_mut <- function(descending) invisible(.Call(wrap__RPola RPolarsSeries$struct_fields <- function() .Call(wrap__RPolarsSeries__struct_fields, self) +RPolarsSeries$struct_unnest <- function() .Call(wrap__RPolarsSeries__struct_unnest, self) + RPolarsSeries$from_arrow_array_stream_str <- function(name, robj_str) .Call(wrap__RPolarsSeries__from_arrow_array_stream_str, name, robj_str) RPolarsSeries$from_arrow_array_robj <- function(name, array) .Call(wrap__RPolarsSeries__from_arrow_array_robj, name, array) diff --git a/R/series__series.R b/R/series__series.R index 5c3e615c6..9bc1adbee 100644 --- a/R/series__series.R +++ b/R/series__series.R @@ -270,7 +270,11 @@ Series_struct = method_as_active_binding( self, expr_struct_make_sub_ns, fields = method_as_active_binding(function() { unwrap(.pr$Series$struct_fields(pl_series), "in $struct$fields:") - }) + }), + unnest = function() { + .pr$Series$struct_unnest(pl_series) |> + unwrap("in $struct$unnest():") + } ) } ) @@ -1101,8 +1105,6 @@ Series_item = function(index = NULL) { #' #' s$clear(n = 5) Series_clear = function(n = 0) { - # TODO: check whether n < 0 should be removed when resolved upstream - # https://github.com/pola-rs/polars/issues/15421 if (length(n) > 1 || !is.numeric(n) || n < 0) { Err_plain("`n` must be an integer greater or equal to 0.") |> unwrap("in $clear():") diff --git a/src/rust/src/series.rs b/src/rust/src/series.rs index 212690912..b6aed6729 100644 --- a/src/rust/src/series.rs +++ b/src/rust/src/series.rs @@ -505,6 +505,12 @@ impl RPolarsSeries { Ok(ca.fields().iter().map(|s| s.name()).collect()) } + fn struct_unnest(&self) -> RResult { + let ca = self.0.struct_().map_err(polars_to_rpolars_err)?; + let out: pl::DataFrame = ca.clone().into(); + Ok(out.into()) + } + pub fn from_arrow_array_stream_str(name: Robj, robj_str: Robj) -> RResult { let name = robj_to!(str, name)?; let s = crate::arrow_interop::to_rust::arrow_stream_to_series_internal(robj_str)?