jonkeane commented on a change in pull request #10601:
URL: https://github.com/apache/arrow/pull/10601#discussion_r658857664



##########
File path: r/tests/testthat/test-metadata.R
##########
@@ -205,3 +205,47 @@ test_that("metadata of list elements (ARROW-10386)", {
   expect_identical(attr(as.data.frame(tab)$x[[1]], "foo"), "bar")
   expect_identical(attr(as.data.frame(tab)$x[[2]], "baz"), "qux")
 })
+
+test_that("list types roundtrip", {
+  # first an unnamed, nested list
+  df <- tibble::tibble(
+    list = list(
+      list(c("one", "one"), c("two", "two")),
+      list(c("three", "three"), c("four", "four")),
+      list(c("five", "five"), c("six", "six"))
+    )
+  )
+  rb <- record_batch(df)
+  expect_identical(dim(rb), dim(df))
+  expect_equal(rb$schema$list$type, list_of(list_of(string())))
+  # as.data.frame(rb) adds arrow_list + vctrs classes, so we only check 
equivalence
+  expect_equivalent(as.data.frame(rb), df)
+
+  # Now, a named list
+  df <- tibble::tibble(
+    named_list = list(
+      list(a = c("one", "one"), b = c("two", "two")),
+      list(a = c("three", "three"), b = c("four", "four")),
+      list(a = c("five", "five"), b = c("six", "six"))
+    )
+  )
+  rb <- record_batch(df)
+  expect_identical(dim(rb), dim(df))
+  expect_equal(rb$schema$named_list$type, list_of(struct(a = string(), b = 
string())))
+  expect_identical(as.data.frame(rb), df)
+
+  skip("These are not yet supported, ")

Review comment:
       I need to do more with this to support this. It converts ok, but it 
doesn't roundtrip correctly. In the conversion to record batches here, the 
named list of named lists gets turned into a 2 row, 1 column data frame (where 
each cell has three structs named "one_row", "two_row", "three_row"). When in 
fact what we want here is a 3 row, 1 column data frame (where each cell has two 
structs named "a" and "b"). 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to