This is an automated email from the ASF dual-hosted git repository.
npr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new fe323c5 ARROW-8699: [R] Fix automatic r_to_py conversion
fe323c5 is described below
commit fe323c5da3aabd4a41cb650e17265357fc58e7fd
Author: Neal Richardson <[email protected]>
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 <[email protected]>
Signed-off-by: Neal Richardson <[email protected]>
---
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