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

   I didn't get back to this for a few days but felt, as you had also hinted, 
that we might not need the `xprt` helpers. Indeed -- `nanoarrow` can 'print 
pointers as character' in the `%lld` form, and as you reminded me, 
`infer_nanoarrow_schema()` picks the pointer from the tag (if one is there).  [ 
If there was a vote, I would vote for aliasing this to a more evocative second 
name ... ]  So the helper becomes
   
   ```r
   capsule_prep <- function(na) {
       ## pointer addresses for array and schema in 'long long int' format
       arrchr <- nanoarrow::nanoarrow_pointer_addr_chr(na)
       schchr <- 
nanoarrow::nanoarrow_pointer_addr_chr(nanoarrow::infer_nanoarrow_schema(na))
       
       ## 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
   }
   ```
   
   and with that we can pass everything around as hoped for:
   
   ```r
   > narb <- nanoarrow::as_nanoarrow_array( palmerpenguins::penguins )
   > na2 <- capsule_prep(narb)
   > df <- po$from_dataframe(na2)
   > df
   shape: (344, 8)
   
┌───────────┬───────────┬────────────────┬───────────────┬───────────────┬─────────────┬────────┬──────┐
   │ species   ┆ island    ┆ bill_length_mm ┆ bill_depth_mm ┆ flipper_lengt ┆ 
body_mass_g ┆ sex    ┆ year │
   │ ---       ┆ ---       ┆ ---            ┆ ---           ┆ h_mm          ┆ 
---         ┆ ---    ┆ ---  │
   │ cat       ┆ cat       ┆ f64            ┆ f64           ┆ ---           ┆ 
i32         ┆ cat    ┆ i32  │
   │           ┆           ┆                ┆               ┆ i32           ┆   
          ┆        ┆      │
   
╞═══════════╪═══════════╪════════════════╪═══════════════╪═══════════════╪═════════════╪════════╪══════╡
   │ Adelie    ┆ Torgersen ┆ 39.1           ┆ 18.7          ┆ 181           ┆ 
3750        ┆ male   ┆ 2007 │
   │ Adelie    ┆ Torgersen ┆ 39.5           ┆ 17.4          ┆ 186           ┆ 
3800        ┆ female ┆ 2007 │
   │ Adelie    ┆ Torgersen ┆ 40.3           ┆ 18.0          ┆ 195           ┆ 
3250        ┆ female ┆ 2007 │
   │ Adelie    ┆ Torgersen ┆ null           ┆ null          ┆ null          ┆ 
null        ┆ null   ┆ 2007 │
   │ Adelie    ┆ Torgersen ┆ 36.7           ┆ 19.3          ┆ 193           ┆ 
3450        ┆ female ┆ 2007 │
   │ …         ┆ …         ┆ …              ┆ …             ┆ …             ┆ … 
          ┆ …      ┆ …    │
   │ Chinstrap ┆ Dream     ┆ 55.8           ┆ 19.8          ┆ 207           ┆ 
4000        ┆ male   ┆ 2009 │
   │ Chinstrap ┆ Dream     ┆ 43.5           ┆ 18.1          ┆ 202           ┆ 
3400        ┆ female ┆ 2009 │
   │ Chinstrap ┆ Dream     ┆ 49.6           ┆ 18.2          ┆ 193           ┆ 
3775        ┆ male   ┆ 2009 │
   │ Chinstrap ┆ Dream     ┆ 50.8           ┆ 19.0          ┆ 210           ┆ 
4100        ┆ male   ┆ 2009 │
   │ Chinstrap ┆ Dream     ┆ 50.2           ┆ 18.7          ┆ 198           ┆ 
3775        ┆ female ┆ 2009 │
   
└───────────┴───────────┴────────────────┴───────────────┴───────────────┴─────────────┴────────┴──────┘
   > 


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