eddelbuettel commented on issue #810:
URL:
https://github.com/apache/arrow-nanoarrow/issues/810#issuecomment-3335902755
A slightly refined and cleaned up version, which needs a small extension to
the archived `xptr` CRAN package (which I'll likely resurrect and re-send to
CRAN, author/former maintainer is on board) to create '%lld' output which we
can `r_to_py()` so that `int()` can take them:
```r
capsule_prep <- function(na) {
## pointer addresses for array and schema in 'long long int' format
arrchr <- xptr::xptr_address(na, FALSE)
schchr <- xptr::xptr_address(xptr::xptr_tag(na), FALSE)
## Import with convert = FALSE so that `_import_from_c` returns a Python
object
py <- reticulate::import_builtins(convert = FALSE)
pa <- reticulate::import("pyarrow", convert = FALSE)
out <- pa$Array$`_import_from_c`(py$int(reticulate::r_to_py(arrchr)),
py$int(reticulate::r_to_py(schchr)))
out
}
```
If I wrap that around my `nanoarrow`-created `RecordBatch` then I can send
this to Python as in
```r
pa <- import("pyarrow")
na2 <- capsule_prep(narb) # narb is the nanoarrow-create record batch
object
## create a record batch
df <- pa$record_batch(na2)
## which we can turn into a table
## which can be exported to pandas
print(pa$table(df)$to_pandas())
```
The question (mostly to @paleolimbot) now is: can something like this
(possibly without the `xptr` dependence, this is easy to replicate here /
already exists) be injected here in an elegant way / possibly with S3 magic to
be 'automagically' invoked? I am a little unclear on how a `nanoarrow` object
would know it is become a Python object ...
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]