Skip to content

feat(r): Add reticulate/Python integration#817

Merged
paleolimbot merged 9 commits intoapache:mainfrom
paleolimbot:python-integration
Oct 23, 2025
Merged

feat(r): Add reticulate/Python integration#817
paleolimbot merged 9 commits intoapache:mainfrom
paleolimbot:python-integration

Conversation

@paleolimbot
Copy link
Member

This PR adds the s3 generics required to interact with Python objects via reticulate. Thie relies on nanoarrow for Python, which also exposes primitives for interacting with capsules. In theory we wouldn't need nanoarrow for Python for the Python -> R case if we could create and consume PyCapsules but this is at least a good start!

library(nanoarrow)
library(reticulate)

pa <- import("pyarrow", convert = FALSE)

x <- pa$array(c(1, 2, 3))

(array <- as_nanoarrow_array(x))
#> <nanoarrow_array double[3]>
#>  $ length    : int 3
#>  $ null_count: int 0
#>  $ offset    : int 0
#>  $ buffers   :List of 2
#>   ..$ :<nanoarrow_buffer validity<bool>[null] ``
#>   ..$ :<nanoarrow_buffer data<double>[3][24 b]> `1 2 3`
#>  $ dictionary: NULL
#>  $ children  : list()
(py_array <- r_to_py(array))
#> nanoarrow.Array<double>[3]
#> 1.0
#> 2.0
#> 3.0
py_to_r(py_array)
#> <nanoarrow_array double[3]>
#>  $ length    : int 3
#>  $ null_count: int 0
#>  $ offset    : int 0
#>  $ buffers   :List of 2
#>   ..$ :<nanoarrow_buffer validity<bool>[null] ``
#>   ..$ :<nanoarrow_buffer data<double>[3][24 b]> `1 2 3`
#>  $ dictionary: NULL
#>  $ children  : list()

Closes #810.

@paleolimbot paleolimbot marked this pull request as ready for review October 22, 2025 19:29
@paleolimbot
Copy link
Member Author

If there are no objections I'll merge later today!

@paleolimbot paleolimbot merged commit 464bd7c into apache:main Oct 23, 2025
13 checks passed
@paleolimbot paleolimbot deleted the python-integration branch October 23, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[R/Python] PyCapsule layer may need unpacking

1 participant