Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate with_column() #313

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- New method `$explode()` for `DataFrame` and `LazyFrame` (#314).
- New method `$clone()` for `LazyFrame` (#347).
- `$with_column()` is now deprecated (following upstream `polars`). It will be
removed in 0.9.0. It should be replaced with `$with_columns()` (#313).

# polars 0.7.0

Expand Down
1 change: 1 addition & 0 deletions R/dataframe__frame.R
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ DataFrame_with_columns = function(...) {
#' @return DataFrame
#' @details with_column is derived from with_columns but takes only one expression argument
DataFrame_with_column = function(expr) {
warning("`with_column()` is deprecated and will be removed in polars 0.9.0. Please use `with_columns()` instead.")
self$with_columns(expr)
}

Expand Down
5 changes: 4 additions & 1 deletion R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,10 @@ LazyFrame$groupby <- function(exprs, maintain_order) .Call(wrap__LazyFrame__grou

LazyFrame$with_columns <- function(exprs) .Call(wrap__LazyFrame__with_columns, self, exprs)

LazyFrame$with_column <- function(expr) .Call(wrap__LazyFrame__with_column, self, expr)
LazyFrame$with_column <- function(expr) {
warning("`with_column()` is deprecated and will be removed in polars 0.9.0. Please use `with_columns()` instead.")
.Call(wrap__LazyFrame__with_column, self, expr)
}

LazyFrame$with_row_count <- function(name, offset) .Call(wrap__LazyFrame__with_row_count, self, name, offset)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,7 @@ test_that("shrink_dtype", {
f = c("a", "b", "c"),
g = c(0.1, 1.32, 0.12),
h = c(T, NA, F)
)$with_column(pl$col("b")$cast(pl$Int64) * 32L)$select(pl$all()$shrink_dtype())
)$with_columns(pl$col("b")$cast(pl$Int64) * 32L)$select(pl$all()$shrink_dtype())

expect_true(all(mapply(
df$dtypes,
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-expr_arr.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("arr$lengths", {
df = pl$DataFrame(list_of_strs = pl$Series(list(c("a", "b"), "c", character(), list(), NULL)))
l = df$with_column(pl$col("list_of_strs")$arr$lengths()$alias("list_of_strs_lengths"))$to_list()
l = df$with_columns(pl$col("list_of_strs")$arr$lengths()$alias("list_of_strs_lengths"))$to_list()

expect_identical(
l |> lapply(\(x) if (inherits(x, "integer64")) as.numeric(x) else x),
Expand Down Expand Up @@ -424,7 +424,7 @@ test_that("to_struct", {

test_that("eval", {
df = pl$DataFrame(a = list(a = c(1, 8, 3), b = c(4, 5, 2)))
l_act = df$select(pl$all()$cast(pl$dtypes$Float64))$with_column(
l_act = df$select(pl$all()$cast(pl$dtypes$Float64))$with_columns(
pl$concat_list(c("a", "b"))$arr$eval(pl$element()$rank())$alias("rank")
)$to_list()
expect_identical(
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-expr_binary.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ test_that("bin$encode and bin$decode", {
$cast(pl$Binary)
$alias("base64"))

test_hex_decode = encoded_hex$with_column(
test_hex_decode = encoded_hex$with_columns(
pl$col("hex")$bin$decode("hex")$alias("hex_decoded")
)$select(
c("hex_decoded")
Expand All @@ -65,7 +65,7 @@ test_that("bin$encode and bin$decode", {
)
)$to_list()

test_base64_decode = encoded_base64$with_column(
test_base64_decode = encoded_base64$with_columns(
pl$col("base64")$bin$decode("base64")$alias("base64_decoded")
)$select(
c("base64_decoded")
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-lazy_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ test_that("pl$sum", {
# support sum over list of expressions, wildcards or strings
l = list(a = 1:2, b = 3:4, c = 5:6)
expect_identical(
pl$DataFrame(l)$with_column(pl$sum(list("a", "c", 42L)))$to_list(),
pl$DataFrame(l)$with_columns(pl$sum(list("a", "c", 42L)))$to_list(),
c(l, list(sum = c(48L, 50L)))
)
expect_identical(
pl$DataFrame(l)$with_column(pl$sum(list("*")))$to_list(),
pl$DataFrame(l)$with_columns(pl$sum(list("*")))$to_list(),
c(l, list(sum = c(9L, 12L)))
)
expect_identical(
pl$DataFrame(l)$with_column(pl$sum(list(pl$col("a") + pl$col("b"), "c")))$to_list(),
pl$DataFrame(l)$with_columns(pl$sum(list(pl$col("a") + pl$col("b"), "c")))$to_list(),
c(l, list(sum = c(9L, 12L)))
)
})
Expand Down Expand Up @@ -64,13 +64,13 @@ test_that("pl$min pl$max", {

# support sum over list of expressions, wildcards or strings
l = list(a = 1:2, b = 3:4, c = 5:6)
expect_identical(pl$DataFrame(l)$with_column(pl$min(list("a", "c", 42L)))$to_list(), c(l, list(min = c(1:2))))
expect_identical(pl$DataFrame(l)$with_column(pl$max(list("a", "c", 42L)))$to_list(), c(l, list(max = c(42L, 42L))))
expect_identical(pl$DataFrame(l)$with_columns(pl$min(list("a", "c", 42L)))$to_list(), c(l, list(min = c(1:2))))
expect_identical(pl$DataFrame(l)$with_columns(pl$max(list("a", "c", 42L)))$to_list(), c(l, list(max = c(42L, 42L))))


## TODO polars cannot handle wildcards hey wait with testing until after PR
# expect_identical(pl$DataFrame(l)$with_column(pl$max(list("*")))$to_list(),c(l,list(min=c(1:2))))
# expect_identical(pl$DataFrame(l)$with_column(pl$min(list("*")))$to_list(),c(l,list(min=c(1:2))))
# expect_identical(pl$DataFrame(l)$with_columns(pl$max(list("*")))$to_list(),c(l,list(min=c(1:2))))
# expect_identical(pl$DataFrame(l)$with_columns(pl$min(list("*")))$to_list(),c(l,list(min=c(1:2))))
})


Expand Down