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 $is_not() in favor of $not_() #511

Merged
merged 4 commits into from
Nov 14, 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 @@ -7,6 +7,8 @@
columns to these functions will now compute the min/max/sum in each column
separately. Use `pl$min_horizontal()` `pl$max_horizontal()`, and
`pl$sum_horizontal()` instead for rowwise computation (#508).
- `$is_not()` is deprecated and will be removed in 0.12.0. Use `$not_()` instead
(#511).

## What's changed

Expand Down
23 changes: 14 additions & 9 deletions R/expr__expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,23 @@ Expr_mul = Expr_mul = function(other) {
#' @keywords Expr Expr_operators
#' @param other literal or Robj which can become a literal
#' @return Exprs
#' @usage Expr_is_not(other)
#' @usage Expr_not_(other)
#' @docType NULL
#' @format NULL
#' @examples
#' # two syntaxes same result
#' pl$lit(TRUE)$is_not()
#' pl$lit(TRUE)$not_()
#' !pl$lit(TRUE)
Expr_is_not = "use_extendr_wrapper"
Expr_not_ = "use_extendr_wrapper"
#' @export
#' @rdname Expr_is_not
#' @rdname Expr_not_
#' @param x Expr
"!.Expr" = function(x) x$is_not()
"!.Expr" = function(x) x$not_()

Expr_is_not = function() {
warning("`$is_not()` is deprecated and will be removed in 0.12.0. Use `$not_()` instead.")
.pr$Expr$not_(self)
}

#' Less Than <
#' @description lt method and operator
Expand Down Expand Up @@ -2173,7 +2178,7 @@ Expr_over = function(...) {
#' pl$lit(v)$is_unique()$alias("is_unique"),
#' pl$lit(v)$is_first()$alias("is_first"),
#' pl$lit(v)$is_duplicated()$alias("is_duplicated"),
#' pl$lit(v)$is_first()$is_not()$alias("R_duplicated")
#' pl$lit(v)$is_first()$not_()$alias("R_duplicated")
#' )$to_list(),
#' list(
#' is_unique = !v %in% v[duplicated(v)],
Expand All @@ -2200,7 +2205,7 @@ Expr_is_unique = "use_extendr_wrapper"
#' pl$lit(v)$is_unique()$alias("is_unique"),
#' pl$lit(v)$is_first()$alias("is_first"),
#' pl$lit(v)$is_duplicated()$alias("is_duplicated"),
#' pl$lit(v)$is_first()$is_not()$alias("R_duplicated")
#' pl$lit(v)$is_first()$not_()$alias("R_duplicated")
#' )$to_list(),
#' list(
#' is_unique = !v %in% v[duplicated(v)],
Expand All @@ -2222,7 +2227,7 @@ Expr_is_first = "use_extendr_wrapper"
#' @name Expr_is_duplicated
#' @format NULL
#' @details is_duplicated is the opposite of `is_unique()`
#' Looking for R like `duplicated()`?, use `some_expr$is_first()$is_not()`
#' Looking for R like `duplicated()`?, use `some_expr$is_first()$not_()`
#'
#' @examples
#' v = c(1, 1, 2, 2, 3, NA, NaN, Inf)
Expand All @@ -2231,7 +2236,7 @@ Expr_is_first = "use_extendr_wrapper"
#' pl$lit(v)$is_unique()$alias("is_unique"),
#' pl$lit(v)$is_first()$alias("is_first"),
#' pl$lit(v)$is_duplicated()$alias("is_duplicated"),
#' pl$lit(v)$is_first()$is_not()$alias("R_duplicated")
#' pl$lit(v)$is_first()$not_()$alias("R_duplicated")
#' )$to_list(),
#' list(
#' is_unique = !v %in% v[duplicated(v)],
Expand Down
2 changes: 1 addition & 1 deletion R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ Expr$mul <- function(other) .Call(wrap__Expr__mul, self, other)

Expr$div <- function(other) .Call(wrap__Expr__div, self, other)

Expr$is_not <- function() .Call(wrap__Expr__is_not, self)
Expr$not_ <- function() .Call(wrap__Expr__not_, self)

Expr$over <- function(proto_exprs) .Call(wrap__Expr__over, self, proto_exprs)

Expand Down
4 changes: 2 additions & 2 deletions man/Expr_is_duplicated.Rd

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

2 changes: 1 addition & 1 deletion man/Expr_is_first.Rd

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

2 changes: 1 addition & 1 deletion man/Expr_is_unique.Rd

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

8 changes: 4 additions & 4 deletions man/Expr_is_not.Rd → man/Expr_not_.Rd

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

2 changes: 1 addition & 1 deletion src/rust/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ impl Expr {
}

//unary
pub fn is_not(&self) -> Self {
pub fn not_(&self) -> Self {
self.0.clone().not().into()
}

Expand Down
22 changes: 11 additions & 11 deletions tests/testthat/test-expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ test_that("expression boolean operators", {

cmp_operators_df = pl$DataFrame(list())$with_columns(
(pl$lit(1) < 2)$alias("1 lt 2"),
(pl$lit(1) < 1)$alias("1 lt 1 not")$is_not(),
(pl$lit(1) < 1)$alias("1 lt 1 not")$not_(),
(pl$lit(2) > 1)$alias("2 gt 1"),
(pl$lit(1) > 1)$alias("1 gt 1 not")$is_not(),
(pl$lit(1) > 1)$alias("1 gt 1 not")$not_(),
(pl$lit(1) == 1)$alias("1 eq 1"),
(pl$lit(1) == 2)$alias("1 eq 2 not")$is_not(),
(pl$lit(1) == 2)$alias("1 eq 2 not")$not_(),
(pl$lit(1) <= 1)$alias("1 lt_eq 1"),
(pl$lit(2) <= 1)$alias("2 lt_eq 1 not")$is_not(),
(pl$lit(2) <= 1)$alias("2 lt_eq 1 not")$not_(),
(pl$lit(2) >= 2)$alias("2 gt_eq 2"),
(pl$lit(1) >= 2)$alias("1 gt_eq 2 not")$is_not(),
(pl$lit(1) >= 2)$alias("1 gt_eq 2 not")$not_(),
(pl$lit(2) != 1)$alias("2 not eq 1"),
(pl$lit(2) != 2)$alias("2 not eq 1 not")$is_not(),
(pl$lit(TRUE)$is_not() == pl$lit(FALSE))$alias("not true == false"),
(pl$lit(2) != 2)$alias("2 not eq 1 not")$not_(),
(pl$lit(TRUE)$not_() == pl$lit(FALSE))$alias("not true == false"),
(pl$lit(TRUE) != pl$lit(FALSE))$alias("true != false"),
(pl$lit(TRUE)$is_not() == FALSE)$alias("not true == false wrap"),
(pl$lit(TRUE)$not_() == FALSE)$alias("not true == false wrap"),
(pl$lit(TRUE) != FALSE)$alias("true != false wrap")
)

Expand Down Expand Up @@ -248,7 +248,7 @@ test_that("is_null", {

expect_equal(
df$with_columns(pl$all()$is_not_null()$name$suffix("_isnull"))$to_data_frame(),
df$with_columns(pl$all()$is_null()$is_not()$name$suffix("_isnull"))$to_data_frame()
df$with_columns(pl$all()$is_null()$not_()$name$suffix("_isnull"))$to_data_frame()
)
})

Expand Down Expand Up @@ -466,7 +466,7 @@ test_that("and or is_in xor", {
pl$lit(NA_real_)$is_in(pl$lit(NULL))$alias("NULL typed is in NULL")

# anymore from rust-polars 0.30-0.32
# pl$lit(NULL)$is_in(pl$lit(NULL))$is_not()$alias("NULL is in NULL, NOY")
# pl$lit(NULL)$is_in(pl$lit(NULL))$not_()$alias("NULL is in NULL, NOY")
)$to_data_frame() |> unlist() |> all(na.rm = TRUE)
)
})
Expand Down Expand Up @@ -1269,7 +1269,7 @@ test_that("is_unique is_first is_duplicated", {
pl$lit(v)$is_unique()$alias("is_unique"),
pl$lit(v)$is_first()$alias("is_first"),
pl$lit(v)$is_duplicated()$alias("is_duplicated"),
pl$lit(v)$is_first()$is_not()$alias("R_duplicated")
pl$lit(v)$is_first()$not_()$alias("R_duplicated")
)$to_list(),
list(
is_unique = !v %in% v[duplicated(v)],
Expand Down
Loading