You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/07/07 15:01:16 UTC

[GitHub] [arrow] nealrichardson commented on a change in pull request #7648: ARROW-8301: [R] Handle ChunkedArray and Table in C data interface

nealrichardson commented on a change in pull request #7648:
URL: https://github.com/apache/arrow/pull/7648#discussion_r450932956



##########
File path: r/R/python.R
##########
@@ -73,6 +73,44 @@ r_to_py.RecordBatch <- function(x, convert = FALSE) {
   out
 }
 
+r_to_py.ChunkedArray <- function(x, convert = FALSE) {
+  # Import with convert = FALSE so that `_import_from_c` returns a Python object
+  pa <- reticulate::import("pyarrow", convert = FALSE)
+  out <- pa$chunked_array(x$chunks)
+  # But set the convert attribute on the return object to the requested value
+  assign("convert", convert, out)
+  out
+}
+
+py_to_r.pyarrow.lib.ChunkedArray <- function(x, ...) {
+  ChunkedArray$create(!!!maybe_py_to_r(x$chunks))
+}
+
+r_to_py.Table <- function(x, convert = FALSE) {
+  # Import with convert = FALSE so that `_import_from_c` returns a Python object
+  pa <- reticulate::import("pyarrow", convert = FALSE)
+  out <- pa$Table$from_arrays(x$columns, names = names(x))
+  # But set the convert attribute on the return object to the requested value
+  assign("convert", convert, out)
+  out
+}
+
+py_to_r.pyarrow.lib.Table <- function(x, ...) {
+  colnames <- maybe_py_to_r(x$column_names)
+  r_cols <- maybe_py_to_r(x$columns)
+  names(r_cols) <- colnames
+  Table$create(!!!r_cols)

Review comment:
       It's like doing `**kwargs`




----------------------------------------------------------------
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.

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