Skip to content

Commit

Permalink
tests, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Apr 2, 2024
1 parent ad9c8a8 commit 8a10f52
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
- New methods `$select_seq()` and `$with_columns_seq()` for `DataFrame` and
`LazyFrame` (#1003).
- New method `$clear()` for `DataFrame`, `LazyFrame`, and `Series` (#1004).
- New method `$struct$unnest()` for `Series` (#1010).

### Bug fixes

Expand Down
8 changes: 8 additions & 0 deletions R/series__series.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ Series_struct = method_as_active_binding(
fields = method_as_active_binding(function() {
unwrap(.pr$Series$struct_fields(pl_series), "in $struct$fields:")
}),
#' Convert this struct Series to a DataFrame with a separate column for
#' each field
#'
#' @name Series_struct_unnest
#' @return A DataFrame
#' @examples
#' s = pl$Series(values = c(1, 2), dtype = pl$Struct(foo = pl$Float64))
#' s$struct$unnest()
unnest = function() {
.pr$Series$struct_unnest(pl_series) |>
unwrap("in $struct$unnest():")
Expand Down
21 changes: 21 additions & 0 deletions man/Series_struct_unnest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions tests/testthat/_snaps/after-wrappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,11 @@
[37] "rep" "set_sorted_mut"
[39] "shape" "sleep"
[41] "sort_mut" "std"
[43] "struct_fields" "sub"
[45] "sum" "to_fmt_char"
[47] "to_frame" "to_r"
[49] "value_counts" "var"
[43] "struct_fields" "struct_unnest"
[45] "sub" "sum"
[47] "to_fmt_char" "to_frame"
[49] "to_r" "value_counts"
[51] "var"

# public and private methods of each class RThreadHandle

Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-series.R
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,17 @@ test_that("$clear() works", {
"greater or equal to 0"
)
})

test_that("$struct$unnest() works", {
s = pl$Series(values = c(1, 2), dtype = pl$Struct(foo = pl$Float64))
expect_identical(
s$struct$unnest()$to_list(),
list(foo = c(1, 2))
)
# empty Series
s = pl$Series(dtype = pl$Struct(foo = pl$Float64))
expect_identical(
s$struct$unnest()$to_list(),
list(foo = numeric(0))
)
})

0 comments on commit 8a10f52

Please sign in to comment.