Skip to content
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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tidypolars
Type: Package
Title: More Efficient Tidyverse Code, Using Polars in the Background
Version: 0.14.1
Version: 0.14.1.9000
Authors@R:
c(person(given = "Etienne",
family = "Bacher",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# tidypolars (development)

## New features

* Add partial support for `stringr::str_equal()` (#228).

# tidypolars 0.14.1

* `tidypolars` requires `polars` >= 1.1.0 (#222).
Expand Down
11 changes: 6 additions & 5 deletions R/funs-string.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ pl_str_dup_stringr <- function(string, times) {
)
}

# TODO: this requires https://github.com/pola-rs/polars/issues/11455
# pl_str_equal_string <- function(x, y, ...) {
#
# }

pl_str_ends_stringr <- function(string, pattern, negate = FALSE, ...) {
check_empty_dots(...)
pattern <- check_pattern(pattern)
Expand All @@ -76,6 +71,12 @@ pl_str_ends_stringr <- function(string, pattern, negate = FALSE, ...) {
out
}

pl_str_equal_stringr <- function(x, y, ...) {
check_empty_dots(...)
x$str$normalize("NFC") == y$str$normalize("NFC")
}


# group = 0 means the whole match
pl_str_extract_stringr <- function(string, pattern, group = 0, ...) {
check_empty_dots(...)
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-funs-string-lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,26 @@ test_that("substr() works", {
)
})

test_that("str_equal() works", {
# need equal length of inputs
length <- sample(0:10, 1)

for_all(
tests = 40,
x = character_(any_na = TRUE, len = length),
y = character_(any_na = TRUE, len = length),
property = function(x, y) {
test_df <- data.frame(x = x, y = y)
test <- as_polars_lf(test_df)

expect_equal_or_both_error(
mutate(test, foo = str_equal(x, y)) |>
pull(foo),
mutate(test_df, foo = str_equal(x, y)) |>
pull(foo)
)
}
)
})

Sys.setenv('TIDYPOLARS_TEST' = FALSE)
22 changes: 22 additions & 0 deletions tests/testthat/test-funs-string.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,25 @@ test_that("substr() works", {
}
)
})

test_that("str_equal() works", {
# need equal length of inputs
length <- sample(0:10, 1)

for_all(
tests = 40,
x = character_(any_na = TRUE, len = length),
y = character_(any_na = TRUE, len = length),
property = function(x, y) {
test_df <- data.frame(x = x, y = y)
test <- as_polars_df(test_df)

expect_equal_or_both_error(
mutate(test, foo = str_equal(x, y)) |>
pull(foo),
mutate(test_df, foo = str_equal(x, y)) |>
pull(foo)
)
}
)
})
27 changes: 27 additions & 0 deletions tests/testthat/test-funs_string-lazy.R
Original file line number Diff line number Diff line change
Expand Up @@ -1233,4 +1233,31 @@ test_that("stringr::str_replace_na works", {
)
})

test_that("str_equal() works", {
test_df <- data.frame(x = c("\u00e1", "\u2126"), y = c("a\u0301", "\u03A9"))
test <- as_polars_lf(test_df)

expect_equal_lazy(
mutate(test, eq = str_equal(x, y)) |>
pull(eq),
mutate(test_df, eq = str_equal(x, y)) |>
pull(eq)
)

expect_warning(
mutate(test, eq = str_equal(x, y, ignore_case = TRUE)),
"doesn't know how to use some arguments"
)

test_df <- data.frame(x = character(), y = character())
test <- as_polars_lf(test_df)

expect_equal_lazy(
mutate(test, eq = str_equal(x, y)) |>
pull(eq),
mutate(test_df, eq = str_equal(x, y)) |>
pull(eq)
)
})

Sys.setenv('TIDYPOLARS_TEST' = FALSE)
27 changes: 27 additions & 0 deletions tests/testthat/test-funs_string.R
Original file line number Diff line number Diff line change
Expand Up @@ -1228,3 +1228,30 @@ test_that("stringr::str_replace_na works", {
error = TRUE
)
})

test_that("str_equal() works", {
test_df <- data.frame(x = c("\u00e1", "\u2126"), y = c("a\u0301", "\u03A9"))
test <- as_polars_df(test_df)

expect_equal(
mutate(test, eq = str_equal(x, y)) |>
pull(eq),
mutate(test_df, eq = str_equal(x, y)) |>
pull(eq)
)

expect_warning(
mutate(test, eq = str_equal(x, y, ignore_case = TRUE)),
"doesn't know how to use some arguments"
)

test_df <- data.frame(x = character(), y = character())
test <- as_polars_df(test_df)

expect_equal(
mutate(test, eq = str_equal(x, y)) |>
pull(eq),
mutate(test_df, eq = str_equal(x, y)) |>
pull(eq)
)
})
1 change: 1 addition & 0 deletions vignettes/r-and-polars-expressions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ out <- tribble(
"`stringr`", "`str_detect`",
"`stringr`", "`str_dup`",
"`stringr`", "`str_ends`",
"`stringr`", "`str_equal`",
"`stringr`", "`str_extract`",
"`stringr`", "`str_extract_all`",
"`stringr`", "`str_length`",
Expand Down
Loading