paleolimbot commented on issue #810:
URL: 
https://github.com/apache/arrow-nanoarrow/issues/810#issuecomment-3339112298

   Thank you for this!
   
   We probably don't need xptr (I beleive `infer_nanoarrow_schema()` will get 
you the external pointer you're looking for from an array).
   
   Perhaps the `nanoarrow` Python package can help here?
   
   ``` r
   library(nanoarrow)
   library(reticulate)
   
   na <- reticulate::import("nanoarrow.c_array", convert = FALSE)
   dst <- na$allocate_c_array()
   dst_addr <- reticulate::py_str(dst[["_addr"]]())
   dst_schema_addr <- reticulate::py_str(dst$schema[["_addr"]]())
   
   arr <- as_nanoarrow_array(data.frame(x = 1:10))
   nanoarrow_pointer_export(arr, dst_addr)
   nanoarrow_pointer_export(infer_nanoarrow_schema(arr), dst_schema_addr)
   
   dst
   #> <nanoarrow.c_array.CArray struct<x: int32>>
   #> - length: 10
   #> - offset: 0
   #> - null_count: 0
   #> - buffers: (0,)
   #> - dictionary: NULL
   #> - children[1]:
   #>   'x': <nanoarrow.c_array.CArray int32>
   #>     - length: 10
   #>     - offset: 0
   #>     - null_count: 0
   #>     - buffers: (0, 4684873592)
   #>     - dictionary: NULL
   #>     - children[0]:
   
   pl <- reticulate::import("polars")
   pl$from_arrow(dst)
   #> shape: (10, 1)
   #> ┌─────┐
   #> │ x   │
   #> │ --- │
   #> │ i32 │
   #> ╞═════╡
   #> │ 1   │
   #> │ 2   │
   #> │ 3   │
   #> │ 4   │
   #> │ 5   │
   #> │ 6   │
   #> │ 7   │
   #> │ 8   │
   #> │ 9   │
   #> │ 10  │
   #> └─────┘
   ```
   
   <sup>Created on 2025-09-26 with [reprex 
v2.1.1](https://reprex.tidyverse.org)</sup>


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

Reply via email to