Skip to content

Commit aa03eec

Browse files
committed
Use setDT when applying metadata
1 parent 683f761 commit aa03eec

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

r/R/metadata.R

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ apply_arrow_r_metadata <- function(x, r_metadata) {
228228
attr(x, ".group_vars") <- NULL
229229
attr(x, ".group_by_drop") <- NULL
230230
}
231+
# GH-45300: Prevent warning about "Invalid .internal.selfref..."
232+
if (inherits(x, "data.table") && requireNamespace("data.table", quietly = TRUE)) {
233+
data.table::setDT(x)
234+
}
231235
}
232236
},
233237
error = function(e) {

r/tests/testthat/test-metadata.R

+19
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,22 @@ test_that("data.frame class attribute is not saved", {
486486
df_arrow <- arrow_table(df)
487487
expect_identical(df_arrow$r_metadata, list(attributes = list(foo = "bar"), columns = list(x = NULL)))
488488
})
489+
490+
test_that("data.tables don't warn when read back in from parquet", {
491+
# See GH-45300
492+
skip_if_not_installed("data.table")
493+
494+
tf <- tempfile()
495+
on.exit(unlink(tf))
496+
497+
dt_in <- data.table::data.table(x = 1:3)
498+
arrow::write_parquet(dt_in, tf)
499+
dt_out <- read_parquet(tf)
500+
501+
expect_no_warning({
502+
dt_out <- dt_out[, z := 4:6]
503+
})
504+
# testthat will skip this entire test if we don't have another assertion
505+
# so we need this here
506+
expect_equal(ncol(dt_out), 2)
507+
})

0 commit comments

Comments
 (0)