Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Apr 2, 2024
1 parent 3c0d0ec commit ad9c8a8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions R/series__series.R
Original file line number Diff line number Diff line change
Expand Up @@ -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():")
}
)
}
)
Expand Down Expand Up @@ -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():")
Expand Down
6 changes: 6 additions & 0 deletions src/rust/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ impl RPolarsSeries {
Ok(ca.fields().iter().map(|s| s.name()).collect())
}

fn struct_unnest(&self) -> RResult<RPolarsDataFrame> {
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<Robj> {
let name = robj_to!(str, name)?;
let s = crate::arrow_interop::to_rust::arrow_stream_to_series_internal(robj_str)?
Expand Down

0 comments on commit ad9c8a8

Please sign in to comment.