-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
S3 methods for DataFrame and LazyFrame: simplest (#107)
* S3 methods for DataFrame and LazyFrame: simplest * @nord tags * remove upper case duplicates (docs warning) * s3: patrick + series + agg * docs * vignette * vignette * vignette * prefix, maintain_order not sort, drop cliffhanger * responses to Grant's comments on Get Started vignette * typo --------- Co-authored-by: sorhawell <[email protected]>
- Loading branch information
1 parent
99e5cd3
commit e9d98de
Showing
10 changed files
with
500 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
#' @export | ||
#' @noRd | ||
head.DataFrame = function(x, n = 6L, ...) x$limit(n = n) | ||
|
||
#' @export | ||
#' @noRd | ||
head.LazyFrame = head.DataFrame | ||
|
||
#' @export | ||
#' @noRd | ||
tail.DataFrame = function(x, n = 6L, ...) x$tail(n = n) | ||
|
||
#' @export | ||
#' @noRd | ||
tail.LazyFrame = tail.DataFrame | ||
|
||
#' @export | ||
#' @noRd | ||
dim.DataFrame = function(x, ...) x$shape | ||
|
||
#' @export | ||
#' @noRd | ||
dim.LazyFrame = function(x, ...) x$collect()$shape | ||
|
||
#' @export | ||
#' @noRd | ||
length.DataFrame = function(x, ...) x$width | ||
|
||
#' @export | ||
#' @noRd | ||
length.Series = function(x, ...) x$len() | ||
|
||
#' @export | ||
#' @noRd | ||
length.LazyFrame = function(x, ...) x$collect()$width | ||
|
||
#' The Number of Rows of a DataFrame | ||
#' @param x DataFrame | ||
#' @return Integer | ||
#' @export | ||
nrow.DataFrame = function(x) x$height | ||
|
||
#' The Number of Rows of a LazyFrame | ||
#' @param x LazyFrame | ||
#' @return Integer | ||
#' @export | ||
nrow.LazyFrame = function(x) x$collect()$height | ||
|
||
#' The Number of Columns of a DataFrame | ||
#' @param x DataFrame | ||
#' @return Integer | ||
#' @export | ||
ncol.DataFrame = function(x) x$height | ||
|
||
#' The Number of Columns of a LazyFrame | ||
#' @param x LazyFrame | ||
#' @return Integer | ||
#' @export | ||
ncol.LazyFrame = function(x) x$collect()$height | ||
|
||
#' @export | ||
#' @noRd | ||
names.DataFrame = function(x) x$columns | ||
|
||
# TODO: inefficient to collect, but attribute is missing | ||
#' @export | ||
#' @noRd | ||
names.LazyFrame = function(x) x$collect()$columns | ||
|
||
# TODO: inefficient to collect, but attribute is missing | ||
#' @export | ||
#' @noRd | ||
as.data.frame.LazyFrame = function(x, ...) x$collect()$as_data_frame(...) | ||
|
||
#' @export | ||
#' @noRd | ||
as.matrix.DataFrame = function(x, ...) as.matrix(x$as_data_frame(...)) | ||
|
||
# TODO: inefficient to collect, but attribute is missing | ||
#' @export | ||
#' @noRd | ||
as.matrix.LazyFrame = function(x, ...) as.matrix(x$collect()$as_data_frame(...)) | ||
|
||
#' @export | ||
#' @noRd | ||
mean.DataFrame = function(x, ...) x$mean() | ||
|
||
#' @export | ||
#' @noRd | ||
mean.LazyFrame = function(x, ...) x$mean() | ||
|
||
#' @export | ||
#' @importFrom stats median | ||
#' @noRd | ||
median.DataFrame = function(x, ...) x$median() | ||
|
||
#' @export | ||
#' @importFrom stats median | ||
#' @noRd | ||
median.LazyFrame = function(x, ...) x$median() | ||
|
||
#' @export | ||
#' @noRd | ||
min.DataFrame = function(x, ...) x$min() | ||
|
||
#' @export | ||
#' @noRd | ||
min.LazyFrame = function(x, ...) x$min() | ||
|
||
#' @export | ||
#' @noRd | ||
min.Series = function(x, ...) x$min() | ||
|
||
#' @export | ||
#' @noRd | ||
max.DataFrame = function(x, ...) x$max() | ||
|
||
#' @export | ||
#' @noRd | ||
max.LazyFrame = function(x, ...) x$max() | ||
|
||
#' @export | ||
#' @noRd | ||
max.Series = function(x, ...) x$max() | ||
|
||
#' @export | ||
#' @noRd | ||
sum.DataFrame = function(x, ...) x$sum() | ||
|
||
#' @export | ||
#' @noRd | ||
sum.LazyFrame = function(x, ...) x$sum() | ||
|
||
#' @export | ||
#' @noRd | ||
sum.Series = function(x, ...) x$sum() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
make_cases <- function() { | ||
tibble::tribble( | ||
~ .test_name, ~ pola, ~ base, | ||
"mean", "mean", mean, | ||
"median", "median", stats::median, | ||
"min", "min", min, | ||
"max", "max", max, | ||
"sum", "sum", sum, | ||
) | ||
} | ||
patrick::with_parameters_test_that("aggregations", | ||
{ | ||
d = pl$DataFrame(mtcars) | ||
w = d[[pola]]()$as_data_frame() | ||
x = base(d)$as_data_frame() | ||
y = base(d$lazy())$collect()$as_data_frame() | ||
z = data.frame(t(sapply(mtcars, base))) | ||
expect_equal(w, x, ignore_attr = TRUE) | ||
expect_equal(w, y, ignore_attr = TRUE) | ||
expect_equal(w, z, ignore_attr = TRUE) | ||
}, | ||
.cases = make_cases() | ||
) | ||
|
||
|
||
make_cases <- function() { | ||
tibble::tribble( | ||
~ .test_name, ~ FUN, | ||
"head", head, | ||
"tail", tail, | ||
"nrow", nrow, | ||
"ncol", ncol, | ||
"length", length, | ||
"as.matrix", as.matrix, | ||
"names", names, | ||
) | ||
} | ||
patrick::with_parameters_test_that("inspection", | ||
{ | ||
d = pl$DataFrame(mtcars) | ||
x = FUN(mtcars) | ||
y = FUN(d) | ||
z = FUN(d$lazy()) | ||
if (inherits(y, "DataFrame")) y = y$as_data_frame() | ||
if (inherits(z, "LazyFrame")) z = z$collect()$as_data_frame() | ||
expect_equal(x, y, ignore_attr = TRUE) | ||
expect_equal(x, z, ignore_attr = TRUE) | ||
}, | ||
.cases = make_cases() | ||
) | ||
|
||
|
||
make_cases <- function() { | ||
tibble::tribble( | ||
~ .test_name, ~ pola, ~ base, | ||
"length", "len", length, | ||
"min", "min", min, | ||
"max", "max", max, | ||
"sum", "sum", sum, | ||
) | ||
} | ||
patrick::with_parameters_test_that("Series", | ||
{ | ||
d = pl$Series(mtcars$mpg) | ||
x = base(mtcars$mpg) | ||
y = base(d) | ||
z = d[[pola]]() | ||
if (inherits(y, "Series")) y = y$to_r_vector() | ||
if (inherits(z, "Series")) z = z$to_r_vector() | ||
expect_equal(x, y, ignore_attr = TRUE) | ||
expect_equal(x, z, ignore_attr = TRUE) | ||
}, | ||
.cases = make_cases() | ||
) |
Oops, something went wrong.