Skip to content

Commit

Permalink
Remove $to_struct() for Expr (#1092)
Browse files Browse the repository at this point in the history
Co-authored-by: eitsupi <[email protected]>
  • Loading branch information
etiennebacher and eitsupi authored May 13, 2024
1 parent edfd798 commit 3f05b41
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 62 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Polars R Package (development version)

### Breaking changes

- `$to_struct()` on an Expr is removed. This method is now only available for
`Series`, `DataFrame`, and in the `$list` and `$arr` subnamespaces. For example,
`pl$col("a", "b", "c")$to_struct()` should be replaced with
`pl$struct(c("a", "b", "c"))` (#1092).

## Polars R Package 0.16.4

### New features
Expand Down
4 changes: 2 additions & 2 deletions R/dataframe__frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,8 @@ DataFrame_to_struct = function(name = "") {
#' c = 6:10
#' )$
#' select(
#' pl$col("b")$to_struct(),
#' pl$col("a", "c")$to_struct()$alias("a_and_c")
#' pl$struct("b"),
#' pl$struct(c("a", "c"))$alias("a_and_c")
#' )
#' df
#'
Expand Down
6 changes: 3 additions & 3 deletions R/datatype.R
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ DataType_Duration = function(time_unit = "us") {
#' )
#' }
#'
#' # Finally, one can use the method `$to_struct()` to convert existing columns
#' # or `Series` to a `Struct`:
#' # Finally, one can use `pl$struct()` to convert existing columns or `Series`
#' # to a `Struct`:
#' x = pl$DataFrame(
#' a = 1:2,
#' b = list(c("x", "y"), "z")
#' )
#'
#' out = x$select(pl$col("a", "b")$to_struct())
#' out = x$select(pl$struct(c("a", "b")))
#' out
#'
#' out$schema
Expand Down
11 changes: 0 additions & 11 deletions R/expr__expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -3199,17 +3199,6 @@ Expr_implode = use_extendr_wrapper
#' df$with_columns(pl$all()$shrink_dtype()$name$suffix("_shrunk"))
Expr_shrink_dtype = use_extendr_wrapper


#' Convert an Expr to a Struct
#' @return Expr
#' @examples
#' pl$DataFrame(iris[, 3:5])$with_columns(
#' my_struct = pl$all()$to_struct()
#' )
Expr_to_struct = function() {
pl$struct(self)
}

#' Convert Literal to Series
#'
#' Collect an expression based on literals into a Series.
Expand Down
4 changes: 2 additions & 2 deletions R/lazyframe__lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -1821,8 +1821,8 @@ LazyFrame_clone = function() {
#' c = 6:10
#' )$
#' select(
#' pl$col("b")$to_struct(),
#' pl$col("a", "c")$to_struct()$alias("a_and_c")
#' pl$struct("b"),
#' pl$struct(c("a", "c"))$alias("a_and_c")
#' )
#' lf$collect()
#'
Expand Down
4 changes: 2 additions & 2 deletions man/DataFrame_unnest.Rd

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

6 changes: 3 additions & 3 deletions man/DataType_Struct.Rd

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

19 changes: 0 additions & 19 deletions man/Expr_to_struct.Rd

This file was deleted.

4 changes: 2 additions & 2 deletions man/LazyFrame_unnest.Rd

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

29 changes: 14 additions & 15 deletions tests/testthat/_snaps/after-wrappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@
[160] "str" "struct" "sub"
[163] "sum" "tail" "tan"
[166] "tanh" "to_physical" "to_r"
[169] "to_series" "to_struct" "top_k"
[172] "unique" "unique_counts" "upper_bound"
[175] "value_counts" "var" "xor"
[169] "to_series" "top_k" "unique"
[172] "unique_counts" "upper_bound" "value_counts"
[175] "var" "xor"

---

Expand Down Expand Up @@ -517,10 +517,10 @@
[160] "std" "str" "struct"
[163] "sub" "sum" "tail"
[166] "tan" "tanh" "to_physical"
[169] "to_r" "to_series" "to_struct"
[172] "top_k" "unique" "unique_counts"
[175] "upper_bound" "value_counts" "var"
[178] "when" "xor"
[169] "to_r" "to_series" "top_k"
[172] "unique" "unique_counts" "upper_bound"
[175] "value_counts" "var" "when"
[178] "xor"

---

Expand Down Expand Up @@ -604,10 +604,10 @@
[160] "std" "str" "struct"
[163] "sub" "sum" "tail"
[166] "tan" "tanh" "to_physical"
[169] "to_r" "to_series" "to_struct"
[172] "top_k" "unique" "unique_counts"
[175] "upper_bound" "value_counts" "var"
[178] "when" "xor"
[169] "to_r" "to_series" "top_k"
[172] "unique" "unique_counts" "upper_bound"
[175] "value_counts" "var" "when"
[178] "xor"

---

Expand Down Expand Up @@ -695,10 +695,9 @@
[169] "sub" "sum" "tail"
[172] "tan" "tanh" "to_frame"
[175] "to_list" "to_lit" "to_physical"
[178] "to_r" "to_struct" "to_vector"
[181] "top_k" "unique" "unique_counts"
[184] "upper_bound" "value_counts" "var"
[187] "xor"
[178] "to_r" "to_vector" "top_k"
[181] "unique" "unique_counts" "upper_bound"
[184] "value_counts" "var" "xor"

---

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,8 @@ test_that("unnest", {

df2 = df$
select(
pl$col("a", "b", "c")$to_struct()$alias("first_struct"),
pl$col("d", "e", "f")$to_struct()$alias("second_struct")
pl$struct(c("a", "b", "c"))$alias("first_struct"),
pl$struct(c("d", "e", "f"))$alias("second_struct")
)

expect_identical(
Expand All @@ -804,7 +804,7 @@ test_that("unnest", {
df$
select(
pl$col("a", "b", "c"),
pl$col("d", "e", "f")$to_struct()$alias("second_struct")
pl$struct(c("d", "e", "f"))$alias("second_struct")
)$
collect()$
to_data_frame()
Expand Down

0 comments on commit 3f05b41

Please sign in to comment.