This is an automated email from the ASF dual-hosted git repository.
kou pushed a commit to branch maint-10.0.x
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/maint-10.0.x by this push:
new 1f9db90db6 MINOR: [R] Fix for dev purrr (#14581)
1f9db90db6 is described below
commit 1f9db90db6f79552a15fb3280d5a7f38464a2352
Author: Hadley Wickham <[email protected]>
AuthorDate: Thu Nov 3 12:00:51 2022 -0500
MINOR: [R] Fix for dev purrr (#14581)
The recycling rules in map2() are now stricter, so we need to check that
`x` actually has columns before applying the metadata.
I also mildly refactored the test to make it easier to run in isolation;
I'm happy to revert those changes if desired.
Authored-by: Hadley Wickham <[email protected]>
Signed-off-by: Neal Richardson <[email protected]>
---
r/R/metadata.R | 8 +++--
r/tests/testthat/test-metadata.R | 65 +++++++++++++++++++---------------------
2 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/r/R/metadata.R b/r/R/metadata.R
index 74080e8f48..550d8bf734 100644
--- a/r/R/metadata.R
+++ b/r/R/metadata.R
@@ -86,9 +86,11 @@ apply_arrow_r_metadata <- function(x, r_metadata) {
call. = FALSE
)
} else {
- x <- map2(x, columns_metadata, function(.x, .y) {
- apply_arrow_r_metadata(.x, .y)
- })
+ if (length(x) > 0) {
+ x <- map2(x, columns_metadata, function(.x, .y) {
+ apply_arrow_r_metadata(.x, .y)
+ })
+ }
}
x
}
diff --git a/r/tests/testthat/test-metadata.R b/r/tests/testthat/test-metadata.R
index 21b7ebe11a..4cf8e49af1 100644
--- a/r/tests/testthat/test-metadata.R
+++ b/r/tests/testthat/test-metadata.R
@@ -254,8 +254,6 @@ test_that("Row-level metadata (does not) roundtrip in
datasets", {
skip_if_not_available("dataset")
skip_if_not_available("parquet")
- library(dplyr, warn.conflicts = FALSE)
-
df <- tibble::tibble(
metadata = list(
structure(1, my_value_as_attr = 1),
@@ -269,39 +267,36 @@ test_that("Row-level metadata (does not) roundtrip in
datasets", {
dst_dir <- make_temp_dir()
- withr::with_options(
- list("arrow.preserve_row_level_metadata" = TRUE),
- {
- expect_warning(
- write_dataset(df, dst_dir, partitioning = "part"),
- "Row-level metadata is not compatible with datasets and will be
discarded"
- )
-
- # Reset directory as previous write will have created some files and the
default
- # behavior is to error on existing
- dst_dir <- make_temp_dir()
- # but we need to write a dataset with row-level metadata to make sure
when
- # reading ones that have been written with them we warn appropriately
- fake_func_name <- write_dataset
- fake_func_name(df, dst_dir, partitioning = "part")
-
- ds <- open_dataset(dst_dir)
- expect_warning(
- df_from_ds <- collect(ds),
- "Row-level metadata is not compatible with this operation and has been
ignored"
- )
- expect_equal(
- arrange(df_from_ds, int),
- arrange(df, int),
- ignore_attr = TRUE
- )
-
- # however there is *no* warning if we don't select the metadata column
- expect_warning(
- df_from_ds <- ds %>% select(int) %>% collect(),
- NA
- )
- }
+ withr::local_options("arrow.preserve_row_level_metadata" = TRUE)
+
+ expect_warning(
+ write_dataset(df, dst_dir, partitioning = "part"),
+ "Row-level metadata is not compatible with datasets and will be discarded"
+ )
+
+ # Reset directory as previous write will have created some files and the
default
+ # behavior is to error on existing
+ dst_dir <- make_temp_dir()
+ # but we need to write a dataset with row-level metadata to make sure when
+ # reading ones that have been written with them we warn appropriately
+ fake_func_name <- write_dataset
+ fake_func_name(df, dst_dir, partitioning = "part")
+
+ ds <- open_dataset(dst_dir)
+ expect_warning(
+ df_from_ds <- collect(ds),
+ "Row-level metadata is not compatible with this operation and has been
ignored"
+ )
+ expect_equal(
+ dplyr::arrange(df_from_ds, int),
+ dplyr::arrange(df, int),
+ ignore_attr = TRUE
+ )
+
+ # however there is *no* warning if we don't select the metadata column
+ expect_warning(
+ df_from_ds <- ds %>% dplyr::select(int) %>% dplyr::collect(),
+ NA
)
})