Skip to content

Commit

Permalink
fix remaining errors
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Nov 17, 2023
1 parent 3d53ec6 commit b7506af
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 52 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
- changes in `$write_csv()` and `sink_csv()`: `has_header` is renamed
`include_header` and there's a new argument `include_bom`.
- `pl$cov()` gains a `ddof` argument.
- `$cumsum()`, `$cumprod()`, `$cummin()`, `$cummax()`, `$cumcount()`, are
- `$cumsum()`, `$cumprod()`, `$cummin()`, `$cummax()`, `$cumcount()` are
renamed `$cum_sum()`, `$cum_prod()`, `$cum_min()`, `$cum_max()`,
`$cum_count()`.
- `take()` and `take_every()` are renamed `$gather()` and `gather_every()`.
- `$shift()` and `$shift_and_fill()` now accept Expr as input.
- when `reverse = TRUE`, `$arg_sort()` now places null values in the first
positions.
- Removed argument `ambiguous` in `$dt$truncate()` and `$dt$round()`.
- `$str$concat()` gains an argument `ignore_nulls`.

## Breaking changes

Expand Down
19 changes: 4 additions & 15 deletions R/expr__datetime.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#' @name ExprDT_truncate
#' @param every string encoding duration see details.
#' @param offset optional string encoding duration see details.
#' @param ambiguous Determine how to deal with ambiguous datetimes:
#' * `"raise"` (default): raise
#' * `"earliest"`: use the earliest datetime
#' * `"latest"`: use the latest datetime
#'
#' @details The ``every`` and ``offset`` argument are created with the
#' the following string language:
Expand Down Expand Up @@ -39,11 +35,8 @@
#' pl$col("datetime")$dt$truncate("4s", offset("3s"))$alias("truncated_4s_offset_2s")
#' )
#' df
ExprDT_truncate = function(
every, # str
offset = NULL, # : str | timedelta | None = None,
ambiguous = "raise") {
.pr$Expr$dt_truncate(self, every, offset, ambiguous) |>
ExprDT_truncate = function(every, offset = NULL) {
.pr$Expr$dt_truncate(self, every, offset) |>
unwrap("in dt$truncate()")
}

Expand All @@ -57,10 +50,6 @@ ExprDT_truncate = function(
#'
#' @param every string encoding duration see details.
#' @param ofset optional string encoding duration see details.
#' @param ambiguous Determine how to deal with ambiguous datetimes:
#' * `"raise"` (default): raise
#' * `"earliest"`: use the earliest datetime
#' * `"latest"`: use the latest datetime
#'
#' @details The ``every`` and ``offset`` argument are created with the
#' the following string language:
Expand Down Expand Up @@ -96,8 +85,8 @@ ExprDT_truncate = function(
#' pl$col("datetime")$dt$truncate("4s", offset("3s"))$alias("truncated_4s_offset_2s")
#' )
#' df
ExprDT_round = function(every, offset = NULL, ambiguous = "raise") {
.pr$Expr$dt_round(self, every, offset, ambiguous) |>
ExprDT_round = function(every, offset = NULL) {
.pr$Expr$dt_round(self, every, offset) |>
unwrap("in dt$round()")
}

Expand Down
8 changes: 6 additions & 2 deletions R/expr__string.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,22 @@ ExprStr_len_chars = function() {
#' @description Vertically concatenate the values in the Series to a single
#' string value.
#' @param delimiter The delimiter to insert between consecutive string values.
#' @param ignore_nulls Ignore null values. If `FALSE`, null values will be
#' propagated: if the column contains any null values, the output is null.
#' @keywords ExprStr
#' @return Expr of Utf8 concatenated
#' @examples
#' # concatenate a Series of strings to a single string
#' df = pl$DataFrame(foo = c("1", NA, 2))
#' df$select(pl$col("foo")$str$concat("-"))
#' df$select(pl$col("foo")$str$concat("-", ignore_nulls = FALSE))
#'
#' # Series list of strings to Series of concatenated strings
#' df = pl$DataFrame(list(bar = list(c("a", "b", "c"), c("1", "2", NA))))
#' df$select(pl$col("bar")$list$eval(pl$col()$str$concat())$list$first())
ExprStr_concat = function(delimiter = "-") {
.pr$Expr$str_concat(self, delimiter)
ExprStr_concat = function(delimiter = "-", ignore_nulls = TRUE) {
.pr$Expr$str_concat(self, delimiter, ignore_nulls) |>
unwrap("in $concat():")
}

#' Convert a string to uppercase
Expand Down
8 changes: 4 additions & 4 deletions R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ Expr$explode <- function() .Call(wrap__Expr__explode, self)

Expr$flatten <- function() .Call(wrap__Expr__flatten, self)

Expr$take_every <- function(n) .Call(wrap__Expr__take_every, self, n)
Expr$gather_every <- function(n) .Call(wrap__Expr__gather_every, self, n)

Expr$hash <- function(seed, seed_1, seed_2, seed_3) .Call(wrap__Expr__hash, self, seed, seed_1, seed_2, seed_3)

Expand Down Expand Up @@ -667,9 +667,9 @@ Expr$str_to_datetime <- function(format, time_unit, time_zone, strict, exact, ca

Expr$str_to_time <- function(format, strict, exact, cache, ambiguous) .Call(wrap__Expr__str_to_time, self, format, strict, exact, cache, ambiguous)

Expr$dt_truncate <- function(every, offset, ambiguous) .Call(wrap__Expr__dt_truncate, self, every, offset, ambiguous)
Expr$dt_truncate <- function(every, offset) .Call(wrap__Expr__dt_truncate, self, every, offset)

Expr$dt_round <- function(every, offset, ambiguous) .Call(wrap__Expr__dt_round, self, every, offset, ambiguous)
Expr$dt_round <- function(every, offset) .Call(wrap__Expr__dt_round, self, every, offset)

Expr$dt_time <- function() .Call(wrap__Expr__dt_time, self)

Expand Down Expand Up @@ -851,7 +851,7 @@ Expr$str_len_bytes <- function() .Call(wrap__Expr__str_len_bytes, self)

Expr$str_len_chars <- function() .Call(wrap__Expr__str_len_chars, self)

Expr$str_concat <- function(delimiter) .Call(wrap__Expr__str_concat, self, delimiter)
Expr$str_concat <- function(delimiter, ignore_nulls) .Call(wrap__Expr__str_concat, self, delimiter, ignore_nulls)

Expr$str_to_uppercase <- function() .Call(wrap__Expr__str_to_uppercase, self)

Expand Down
7 changes: 0 additions & 7 deletions man/ExprDT_round.Rd

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

7 changes: 0 additions & 7 deletions man/ExprDT_truncate.Rd

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

4 changes: 4 additions & 0 deletions man/ExprStr_concat.Rd

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

2 changes: 1 addition & 1 deletion tests/testthat/test-expr.R
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ test_that("Expr explode/flatten", {
})


test_that("take_every", {
test_that("gather_every", {
df = pl$DataFrame(list(a = 0:24))$select(pl$col("a")$gather_every(6))
expect_identical(
df$to_list()[[1L]],
Expand Down
19 changes: 7 additions & 12 deletions tests/testthat/test-expr_string.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test_that("str$strptime datetime", {

expect_error(
pl$lit(txt_datetimes)$str$strptime(pl$Datetime(), format = "%Y-%m-%d %H:%M:%S")$lit_to_s(),
"strict datetime"
"Conversion .* failed"
)

expect_identical(
Expand Down Expand Up @@ -35,7 +35,7 @@ test_that("str$strptime date", {

expect_grepl_error(
pl$lit(txt_dates)$str$strptime(pl$Date, format = "%Y-%m-%d")$lit_to_s(),
"strict date parsing failed"
"Conversion from `str` to `date` failed"
)

expect_identical(
Expand Down Expand Up @@ -69,7 +69,7 @@ test_that("str$strptime time", {

expect_grepl_error(
pl$lit(txt_times)$str$strptime(pl$Time, format = "%H:%M:%S %z")$lit_to_s(),
"strict time parsing failed"
"Conversion from `str` to `time` failed"
)

expect_equal(
Expand All @@ -81,10 +81,6 @@ test_that("str$strptime time", {
)
})





test_that("str$len_bytes str$len_chars", {
test_str = c("Café", NA, "345", "東京") |> enc2utf8()
Encoding(test_str)
Expand Down Expand Up @@ -623,23 +619,22 @@ test_that("str$str_explode", {

test_that("str$parse_int", {
expect_identical(
pl$lit(c("110", "101", "010"))$str$parse_int(2)$to_r(),
pl$lit(c("110", "101", "010"))$str$parse_int(2)$shrink_dtype()$to_r(),
c(6L, 5L, 2L)
)

expect_identical(
pl$lit(c("110", "101", "010"))$str$parse_int()$to_r(),
pl$lit(c("110", "101", "010"))$str$parse_int()$shrink_dtype()$to_r(),
c(6L, 5L, 2L)
)


expect_identical(
pl$lit(c("110", "101", "010"))$str$parse_int(10)$to_r(),
pl$lit(c("110", "101", "010"))$str$parse_int(10)$shrink_dtype()$to_r(),
c(110L, 101L, 10L)
)

expect_identical(
pl$lit(c("110", "101", "hej"))$str$parse_int(10, FALSE)$to_r(),
pl$lit(c("110", "101", "hej"))$str$parse_int(10, FALSE)$shrink_dtype()$to_r(),
c(110L, 101L, NA)
)

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 @@ -251,9 +251,9 @@ test_that("drop_nulls", {
expect_equal(pl$DataFrame(tmp)$lazy()$drop_nulls("mpg")$collect()$height, 29, ignore_attr = TRUE)
expect_equal(pl$DataFrame(tmp)$lazy()$drop_nulls("hp")$collect()$height, 32, ignore_attr = TRUE)
expect_equal(pl$DataFrame(tmp)$lazy()$drop_nulls(c("mpg", "hp"))$collect()$height, 29, ignore_attr = TRUE)
expect_identical(
result(pl$DataFrame(mtcars)$lazy()$drop_nulls("bad")$collect())$err$contexts(),
list(PolarsError = "not found: bad")
expect_error(
pl$DataFrame(mtcars)$lazy()$drop_nulls("bad")$collect(),
"not found: unable to find column \"bad\""
)
})

Expand Down

0 comments on commit b7506af

Please sign in to comment.