Skip to content

Commit

Permalink
Remove dplyr_reconstruct method
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Sep 9, 2023
1 parent 98192f8 commit b5c108d
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 114 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 0 additions & 33 deletions R/dplyr_reconstruct.R
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 0 additions & 11 deletions man/methods_overwrite.Rd

This file was deleted.

11 changes: 0 additions & 11 deletions man/methods_restore.Rd

This file was deleted.

58 changes: 0 additions & 58 deletions tests/testthat/test-generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})

0 comments on commit b5c108d

Please sign in to comment.