Skip to content

Commit

Permalink
Transition from tinytest to testthat (#142)
Browse files Browse the repository at this point in the history
* init

* more [skip ci]

* more [skip ci]

* more [skip ci]

* more [skip ci]

* remove tinytest from description [skip ci]

* more [skip ci]

* more [skip ci]

* more [skip ci]

* more [skip ci]

* more [skip ci]

* more [skip ci]

* more [skip ci]

* more [skip ci]

* more [skip ci]

* finish

* remove other mentions of tinytest

* try fix

* fix

---------

Co-authored-by: Etienne Bacher <[email protected]>
  • Loading branch information
etiennebacher and Etienne Bacher authored Sep 26, 2024
1 parent 69d7d8d commit 03a0121
Show file tree
Hide file tree
Showing 241 changed files with 14,130 additions and 12,658 deletions.
2 changes: 2 additions & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.html

/.quarto/
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ test_pl |>
mutate(ends_with_c = str_ends(x, "c"))
```

Finally, the only thing left to do is to add some tests in the `tests/tinytest`
Finally, the only thing left to do is to add some tests in the `tests/testthat`
folder.

### Testing changes

`tidypolars` uses [`tinytest`](https://cran.r-project.org/web/packages/tinytest/)
`tidypolars` uses [`testthat`](https://cran.r-project.org/web/packages/testthat/)
for checking that functions have the expected output. If changes affect the
behavior of some functions (for example when adding an extra argument), add
some tests in the related file in `tests/tinytest`.
some tests in the related file in `tests/testthat`.

Note that you only need to edit the file with `test_<function name>.R`. Files
ending with `_lazy.R` are automatically generated. Use `devtools::load_all()`
Expand Down
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ Suggests:
stringr,
testthat (>= 3.0.0),
tibble,
tinytest
Remotes:
markvanderloo/tinytest/pkg
withr
VignetteBuilder: knitr
Config/testthat/edition: 3
Config/testthat/parallel: true
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ export(describe)
export(describe_optimized_plan)
export(describe_plan)
export(duplicated_rows)
export(expect_colnames)
export(expect_dim)
export(expect_equal)
export(expect_equal_lazy)
export(expect_error_lazy)
export(expect_is_tidypolars)
export(fetch)
export(make_unique_id)
export(read_csv_polars)
Expand Down
2 changes: 1 addition & 1 deletion R/arrange.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ arrange.RPolarsDataFrame <- function(.data, ..., .by_group = FALSE) {

out <- if (is_grouped) {
.data$sort(vars, descending = direction) |>
group_by(grps, maintain_order = mo)
group_by(all_of(grps), maintain_order = mo)
} else {
.data$sort(vars, descending = direction)
}
Expand Down
2 changes: 1 addition & 1 deletion R/collect.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ compute.RPolarsLazyFrame <- function(

out <- if (is_grouped) {
out |>
group_by(grps, maintain_order = mo)
group_by(all_of(grps), maintain_order = mo)
} else {
out
}
Expand Down
4 changes: 2 additions & 2 deletions R/complete.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ complete.RPolarsDataFrame <- function(data, ..., fill = list()) {

out <- if (is_grouped) {
out |>
relocate(grps, .before = 1) |>
group_by(grps, maintain_order = mo)
relocate(all_of(grps), .before = 1) |>
group_by(all_of(grps), maintain_order = mo)
} else {
out
}
Expand Down
4 changes: 2 additions & 2 deletions R/count.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ count.RPolarsDataFrame <- function(x, ..., sort = FALSE, name = "n") {
out <- count_(x, vars, sort = sort, name = name, new_col = FALSE)

out <- if (is_grouped) {
group_by(out, grps, maintain_order = mo)
group_by(out, all_of(grps), maintain_order = mo)
} else {
out
}
Expand All @@ -51,7 +51,7 @@ add_count.RPolarsDataFrame <- function(x, ..., sort = FALSE, name = "n") {
out <- count_(x, vars, sort = sort, name = name, new_col = TRUE, missing_name = missing(name))

out <- if (is_grouped) {
group_by(out, grps, maintain_order = mo)
group_by(out, all_of(grps), maintain_order = mo)
} else {
out
}
Expand Down
2 changes: 1 addition & 1 deletion R/fill.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fill.RPolarsDataFrame <- function(data, ..., .direction = c("down", "up", "downu

out <- if (is_grouped) {
data$with_columns(expr) |>
group_by(grps, maintain_order = mo)
group_by(all_of(grps), maintain_order = mo)
} else {
data$with_columns(expr)
}
Expand Down
2 changes: 1 addition & 1 deletion R/filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ filter.RPolarsDataFrame <- function(.data, ..., .by = NULL) {
}
)
out <- if (is_grouped && missing(.by)) {
group_by(out, grps, maintain_order = mo)
group_by(out, all_of(grps), maintain_order = mo)
} else {
out
}
Expand Down
77 changes: 67 additions & 10 deletions R/funs-default.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pl_between_dplyr <- function(x, left, right, ...) {
pl_case_match <- function(x, ..., .data) {
env <- env_from_dots(...)
new_vars <- new_vars_from_dots(...)
caller <- caller_from_dots(...)
dots <- clean_dots(...)

x <- polars::pl$col(deparse(substitute(x)))
Expand All @@ -241,12 +242,30 @@ pl_case_match <- function(x, ..., .data) {
out <- NULL
for (y in seq_along(dots)) {
if (y == length(dots)) {
otw <- translate_expr(.data, dots[[y]], new_vars = new_vars, env = env)
otw <- translate_expr(
.data,
dots[[y]],
new_vars = new_vars,
env = env,
caller = caller
)
out <- out$otherwise(otw)
next
}
lhs <- translate_expr(.data, dots[[y]][[2]], new_vars = new_vars, env = env)
rhs <- translate_expr(.data, dots[[y]][[3]], new_vars = new_vars, env = env)
lhs <- translate_expr(
.data,
dots[[y]][[2]],
new_vars = new_vars,
env = env,
caller = caller
)
rhs <- translate_expr(
.data,
dots[[y]][[3]],
new_vars = new_vars,
env = env,
caller = caller
)
if (is.null(out)) {
out <- polars::pl$when(x$is_in(lhs))$then(rhs)
} else {
Expand All @@ -260,6 +279,7 @@ pl_case_match <- function(x, ..., .data) {
pl_case_when <- function(..., .data) {
env <- env_from_dots(...)
new_vars <- new_vars_from_dots(...)
caller <- caller_from_dots(...)
dots <- clean_dots(...)

if (!".default" %in% names(dots)) {
Expand All @@ -269,12 +289,30 @@ pl_case_when <- function(..., .data) {
out <- NULL
for (y in seq_along(dots)) {
if (y == length(dots)) {
otw <- translate_expr(.data, dots[[y]], new_vars = new_vars, env = env)
otw <- translate_expr(
.data,
dots[[y]],
new_vars = new_vars,
env = env,
caller = caller
)
out <- out$otherwise(otw)
next
}
lhs <- translate_expr(.data, dots[[y]][[2]], new_vars = new_vars, env = env)
rhs <- translate_expr(.data, dots[[y]][[3]], new_vars = new_vars, env = env)
lhs <- translate_expr(
.data,
dots[[y]][[2]],
new_vars = new_vars,
env = env,
caller = caller
)
rhs <- translate_expr(
.data,
dots[[y]][[3]],
new_vars = new_vars,
env = env,
caller = caller
)

if (is.null(out)) {
out <- polars::pl$when(lhs)$then(rhs)
Expand Down Expand Up @@ -372,10 +410,29 @@ pl_ifelse <- function(cond, yes, no, .data, ...) {
check_empty_dots(...)
env <- env_from_dots(...)
new_vars <- new_vars_from_dots(...)

cond <- translate_expr(.data, enexpr(cond), new_vars = new_vars, env = env)
yes <- translate_expr(.data, enexpr(yes), new_vars = new_vars, env = env)
no <- translate_expr(.data, enexpr(no), new_vars = new_vars, env = env)
caller <- caller_from_dots(...)

cond <- translate_expr(
.data,
enexpr(cond),
new_vars = new_vars,
env = env,
caller = caller
)
yes <- translate_expr(
.data,
enexpr(yes),
new_vars = new_vars,
env = env,
caller = caller
)
no <- translate_expr(
.data,
enexpr(no),
new_vars = new_vars,
env = env,
caller = caller
)
pl$when(cond)$then(yes)$otherwise(no)
}

Expand Down
2 changes: 1 addition & 1 deletion R/mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mutate.RPolarsDataFrame <- function(
}

out <- if (is_grouped && missing(.by)) {
group_by(.data, grps, maintain_order = mo)
group_by(.data, all_of(grps), maintain_order = mo)
} else if (isTRUE(is_rowwise)) {
rowwise(.data)
} else {
Expand Down
6 changes: 3 additions & 3 deletions R/slice.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ slice_tail.RPolarsDataFrame <- function(.data, ..., n, by = NULL) {
}

out <- if (is_grouped && missing(by)) {
group_by(out, grps, maintain_order = mo)
group_by(out, all_of(grps), maintain_order = mo)
} else {
out
}
Expand Down Expand Up @@ -61,7 +61,7 @@ slice_head.RPolarsDataFrame <- function(.data, ..., n, by = NULL) {
}

out <- if (is_grouped && missing(by)) {
group_by(out, grps, maintain_order = mo)
group_by(out, all_of(grps), maintain_order = mo)
} else {
out
}
Expand Down Expand Up @@ -110,7 +110,7 @@ slice_sample.RPolarsDataFrame <- function(.data, ..., n = NULL, prop = NULL, rep
}

out <- if (is_grouped && missing(by)) {
group_by(out, grps, maintain_order = mo)
group_by(out, all_of(grps), maintain_order = mo)
} else {
out
}
Expand Down
2 changes: 1 addition & 1 deletion R/summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ summarize.RPolarsDataFrame <- function(.data, ..., .by = NULL) {
}

out <- if (is_grouped && missing(.by)) {
group_by(.data, grps, maintain_order = mo)
group_by(.data, all_of(grps), maintain_order = mo)
} else if (isTRUE(is_rowwise)) {
rowwise(.data)
} else {
Expand Down
98 changes: 0 additions & 98 deletions R/tinytest.R

This file was deleted.

Loading

0 comments on commit 03a0121

Please sign in to comment.