From b5c108db78977b5446776beac592d6bc8c3e75bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 9 Sep 2023 22:26:00 +0200 Subject: [PATCH] Remove dplyr_reconstruct method --- NAMESPACE | 1 - R/dplyr_reconstruct.R | 33 ------------------- man/methods_overwrite.Rd | 11 ------- man/methods_restore.Rd | 11 ------- tests/testthat/test-generics.R | 58 ---------------------------------- 5 files changed, 114 deletions(-) delete mode 100644 man/methods_overwrite.Rd delete mode 100644 man/methods_restore.Rd diff --git a/NAMESPACE b/NAMESPACE index b7005f6f..328e1670 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,7 +10,6 @@ S3method(count,duckplyr_df) S3method(cross_join,duckplyr_df) S3method(distinct,duckplyr_df) S3method(do,duckplyr_df) -S3method(dplyr_reconstruct,duckplyr_df) S3method(explain,duckplyr_df) S3method(format,relational_relexpr) S3method(full_join,duckplyr_df) diff --git a/R/dplyr_reconstruct.R b/R/dplyr_reconstruct.R index 94599450..e69de29b 100644 --- a/R/dplyr_reconstruct.R +++ b/R/dplyr_reconstruct.R @@ -1,33 +0,0 @@ -# Generated by 02-duckplyr_df-methods.R -#' @export -dplyr_reconstruct.duckplyr_df <- function(data, template) { - if (inherits(data, c("grouped_df", "rowwise_df"))) { - return(data) - } - .Call(copy_df_attribs, data, template) - return(data) - - # dplyr forward - dplyr_reconstruct <- dplyr$dplyr_reconstruct.data.frame - out <- dplyr_reconstruct(data, template) - return(out) - - # dplyr implementation - attrs <- attributes(template) - attrs$names <- names(data) - attrs$row.names <- .row_names_info(data, type = 0L) - - attributes(data) <- attrs - data -} - -duckplyr_dplyr_reconstruct <- function(data, ...) { - try_fetch( - data <- as_duckplyr_df(data), - error = function(e) { - testthat::skip(conditionMessage(e)) - } - ) - out <- dplyr_reconstruct(data, ...) - out -} diff --git a/man/methods_overwrite.Rd b/man/methods_overwrite.Rd deleted file mode 100644 index 51875b46..00000000 --- a/man/methods_overwrite.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/overwrite.R -\name{methods_overwrite} -\alias{methods_overwrite} -\title{Methods overwriting} -\usage{ -methods_overwrite() -} -\description{ -Methods overwriting -} diff --git a/man/methods_restore.Rd b/man/methods_restore.Rd deleted file mode 100644 index 3f0d65c3..00000000 --- a/man/methods_restore.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/restore.R -\name{methods_restore} -\alias{methods_restore} -\title{Methods restoring} -\usage{ -methods_restore() -} -\description{ -Methods restoring -} diff --git a/tests/testthat/test-generics.R b/tests/testthat/test-generics.R index 505c7257..af7da962 100644 --- a/tests/testthat/test-generics.R +++ b/tests/testthat/test-generics.R @@ -79,61 +79,3 @@ test_that("reconstruct method gets a data frame", { dplyr_row_slice(df, 1) expect_true(seen_df) }) - -# dplyr_reconstruct ------------------------------------------------------- - -test_that("classes are restored", { - expect_identical( - duckplyr_dplyr_reconstruct(tibble(), data.frame()), - data.frame() - ) - expect_identical( - duckplyr_dplyr_reconstruct(tibble(), tibble()), - tibble() - ) - expect_identical( - duckplyr_dplyr_reconstruct(tibble(), new_data_frame(class = "foo")), - new_data_frame(class = "foo") - ) -}) - -test_that("attributes of `template` are kept", { - expect_identical( - duckplyr_dplyr_reconstruct(new_tibble(list(), nrow = 1), new_data_frame(foo = 1)), - new_data_frame(n = 1L, foo = 1) - ) -}) - -test_that("compact row names are retained", { - data <- vec_rbind(tibble(a = 1), tibble(a = 2)) - template <- tibble() - - x <- duckplyr_dplyr_reconstruct(data, template) - expect <- tibble(a = c(1, 2)) - - expect_identical(x, expect) - - # Explicitly ensure internal row name structure is identical - expect_identical( - .row_names_info(x, type = 0L), - .row_names_info(expect, type = 0L) - ) -}) - -test_that("duckplyr_dplyr_reconstruct() strips attributes before dispatch", { - local_methods( - dplyr_reconstruct.dplyr_foobar = function(data, template) { - out <<- data - } - ) - - df <- foobar(data.frame(x = 1), foo = "bar") - out <- NULL - duckplyr_dplyr_reconstruct(df, df) - expect_identical(out, data.frame(x = 1)) - - df <- foobar(data.frame(x = 1, row.names = "a"), foo = "bar") - out <- NULL - duckplyr_dplyr_reconstruct(df, df) - expect_identical(out, data.frame(x = 1, row.names = "a")) -})