You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2020/05/13 01:15:23 UTC
[arrow] 07/17: ARROW-8699: [R] Fix automatic r_to_py conversion
This is an automated email from the ASF dual-hosted git repository.
kszucs pushed a commit to branch maint-0.17.x
in repository https://gitbox.apache.org/repos/asf/arrow.git
commit ddfd4de97bf9317cd3d0c47a48f10b278ed8bf1d
Author: Neal Richardson <ne...@gmail.com>
AuthorDate: Mon May 4 16:04:09 2020 -0700
ARROW-8699: [R] Fix automatic r_to_py conversion
This appears to be the fix for https://github.com/rstudio/reticulate/issues/748
cc @kevinushey
Closes #7102 from nealrichardson/r-to-py
Authored-by: Neal Richardson <ne...@gmail.com>
Signed-off-by: Neal Richardson <ne...@gmail.com>
---
r/R/python.R | 16 ++++++++++++----
r/vignettes/python.Rmd | 2 +-
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/r/R/python.R b/r/R/python.R
index 4d84a40..3964076 100644
--- a/r/R/python.R
+++ b/r/R/python.R
@@ -35,9 +35,13 @@ r_to_py.Array <- function(x, convert = FALSE) {
delete_arrow_array(array_ptr)
})
- pa <- reticulate::import("pyarrow", convert = convert)
+ # Import with convert = FALSE so that `_import_from_c` returns a Python object
+ pa <- reticulate::import("pyarrow", convert = FALSE)
ExportArray(x, array_ptr, schema_ptr)
- pa$Array$`_import_from_c`(array_ptr, schema_ptr)
+ out <- pa$Array$`_import_from_c`(array_ptr, schema_ptr)
+ # But set the convert attribute on the return object to the requested value
+ assign("convert", convert, out)
+ out
}
py_to_r.pyarrow.lib.RecordBatch <- function(x, ...) {
@@ -60,9 +64,13 @@ r_to_py.RecordBatch <- function(x, convert = FALSE) {
delete_arrow_array(array_ptr)
})
- pa <- reticulate::import("pyarrow", convert = convert)
+ # Import with convert = FALSE so that `_import_from_c` returns a Python object
+ pa <- reticulate::import("pyarrow", convert = FALSE)
ExportRecordBatch(x, array_ptr, schema_ptr)
- pa$RecordBatch$`_import_from_c`(array_ptr, schema_ptr)
+ out <- pa$RecordBatch$`_import_from_c`(array_ptr, schema_ptr)
+ # But set the convert attribute on the return object to the requested value
+ assign("convert", convert, out)
+ out
}
#' Install pyarrow for use with reticulate
diff --git a/r/vignettes/python.Rmd b/r/vignettes/python.Rmd
index 5ee5654..c05ee7d 100644
--- a/r/vignettes/python.Rmd
+++ b/r/vignettes/python.Rmd
@@ -84,7 +84,7 @@ to use it efficiently.
```r
b <- Array$create(c(5, 6, 7, 8, 9))
-a_and_b <- pa$concat_arrays(r_to_py(list(a, b)))
+a_and_b <- pa$concat_arrays(list(a, b))
a_and_b
## Array