Skip to content

Commit

Permalink
Add tests for collect()
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher committed Apr 15, 2024
1 parent 2fc2cd2 commit 8505c0c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/collect.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ collect.RPolarsLazyFrame <- function(
) {
if (isTRUE(verbose)) {
rlang::warn(
"As of `tidypolars` 0.8.0, `collect()` will automatically convert the Polars DataFrame to a standard R data.frame. Use `compute()` instead (with the same arguments) to have a Polars DataFrame as output.\nUse `verbose = FALSE` to remove this warning."
"As of `tidypolars` 0.8.0, `collect()` will automatically convert the Polars DataFrame to a standard R data.frame. \nUse `compute()` instead (with the same arguments) to have a Polars DataFrame as output.\nUse `verbose = FALSE` to remove this warning."
)
}
x |>
Expand Down
2 changes: 1 addition & 1 deletion tests/tinytest/setup.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
lf <- list.files("tests/tinytest", pattern = "^test")
eager <- lf[grep("lazy", lf, invert = TRUE)]

exceptions <- c("test_benchmark.R", "test_compute.R",
exceptions <- c("test_benchmark.R", "test_compute.R", "test_collect.R",
"test_describe.R", "test_fetch.R",
"test_group_split.R",
"test_pivot_wider.R", "test_sink_csv.R", "test_sink_parquet.R",
Expand Down
40 changes: 40 additions & 0 deletions tests/tinytest/test_collect.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
source("helpers.R")
using("tidypolars")

pl_iris <- pl$DataFrame(iris)
pl_iris_lazy <- pl$LazyFrame(iris)

expect_warning(
collect(pl_iris_lazy),
"automatically convert the"
)
expect_is_tidypolars(collect(pl_iris_lazy, verbose = FALSE))

expect_equal(
collect(pl_iris_lazy, verbose = FALSE),
pl_iris
)

expect_equal(
pl_iris_lazy |>
filter(Species == "setosa") |>
collect(verbose = FALSE),
pl_iris |>
filter(Species == "setosa")
)

expect_error(collect(pl_iris, verbose = FALSE))

out <- pl_iris_lazy |>
group_by(Species, maintain_order = TRUE) |>
collect(verbose = FALSE)

expect_equal(
attr(out, "pl_grps"),
"Species"
)

expect_equal(
attr(out, "maintain_grp_order"),
TRUE
)

0 comments on commit 8505c0c

Please sign in to comment.