Skip to content

Commit

Permalink
Remove data.table from class attribute
Browse files Browse the repository at this point in the history
Revert "Remove data.table from class attribute"

This reverts commit 9827ff1.

Use setDT when applying metadata
  • Loading branch information
amoeba committed Jan 25, 2025
1 parent c6b6bfb commit 459bde8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions r/R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ apply_arrow_r_metadata <- function(x, r_metadata) {
attr(x, ".group_vars") <- NULL
attr(x, ".group_by_drop") <- NULL
}
# GH-45300: Prevent warning about "Invalid .internal.selfref..."
if (inherits(x, "data.table") && requireNamespace("data.table", quietly = TRUE)) {
data.table::setDT(x)
}
}
},
error = function(e) {
Expand Down
19 changes: 19 additions & 0 deletions r/tests/testthat/test-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,22 @@ test_that("data.frame class attribute is not saved", {
df_arrow <- arrow_table(df)
expect_identical(df_arrow$r_metadata, list(attributes = list(foo = "bar"), columns = list(x = NULL)))
})

test_that("data.tables don't warn when read back in from parquet", {
# See GH-45300
skip_if_not_installed("data.table")

tf <- tempfile()
on.exit(unlink(tf))

dt_in <- data.table::data.table(x = 1:3)
arrow::write_parquet(dt_in, tf)
dt_out <- read_parquet(tf)

expect_no_warning({
dt_out <- dt_out[, z := 4:6]
})
# testthat will skip this entire test if we don't have another assertion
# so we need this here
expect_equal(ncol(dt_out), 2)
})

0 comments on commit 459bde8

Please sign in to comment.