nbenn opened a new issue, #953:
URL: https://github.com/apache/arrow-nanoarrow/issues/953

   Without arrow installed, `as_nanoarrow_array()` fails on an `I()`-wrapped 
base vector, although `infer_nanoarrow_schema()` handles the same value. This 
is on 0.9.0 and on main (8f81815):
   
   ``` r
   library(nanoarrow)
   
   format(infer_nanoarrow_schema(I(1.5)))
   #> [1] "<nanoarrow_schema double>"
   as_nanoarrow_array(I(1.5))
   #> Error: Package 'arrow' required for create double array from object of 
type AsIs
   as_nanoarrow_array(data.frame(x = I(list(as.raw(1:3)))))
   #> Error: Package 'arrow' required for create binary array from object of 
type AsIs
   ```
   
   The data frame is the case that matters in practice: `I()` is how base R 
keeps a list column whole in `data.frame()`, and DBItest writes exactly such a 
column in its 
[`roundtrip_raw`](https://github.com/r-dbi/DBItest/blob/eeea74bb41d129763349fc141a5c57bc92615df8/R/spec-sql-write-table.R#L485-L491)
 test. In adbi, `dbWriteTable()` hands that data frame to nanoarrow as it is, 
so the test needs arrow there.
   
   Since #344, `infer_nanoarrow_schema()` has an `AsIs` method that strips the 
class and dispatches again 
([`r/R/schema.R#L174-L179`](https://github.com/apache/arrow-nanoarrow/blob/8f81815c7a233d3fc697f43c7aed42e82a4f33be/r/R/schema.R#L174-L179)),
 but `as_nanoarrow_array()` has no counterpart. For an `I()` value, the C 
conversion calls back into R with `.from_c = TRUE` 
([`r/R/as-array.R#L471-L472`](https://github.com/apache/arrow-nanoarrow/blob/8f81815c7a233d3fc697f43c7aed42e82a4f33be/r/R/as-array.R#L471-L472)),
 dispatch falls through to the default method, and that hands the value to 
arrow 
([`r/R/as-array.R#L23-L52`](https://github.com/apache/arrow-nanoarrow/blob/8f81815c7a233d3fc697f43c7aed42e82a4f33be/r/R/as-array.R#L23-L52)).
 Classed values such as `I(as.Date("2020-01-01"))` or an `I()`-wrapped blob are 
not affected, because dispatch reaches their own methods.
   
   Would a matching method be welcome? This one mirrors the schema method:
   
   ``` r
   #' @export
   as_nanoarrow_array.AsIs <- function(x, ..., schema = NULL) {
     # NextMethod() goes directly to `default`
     class(x) <- class(x)[-1]
     as_nanoarrow_array(x, schema = schema)
   }
   ```
   
   Built from 8f81815 with this method, both calls above return arrays without 
arrow (`convert_array()` gives back `1.5` and a one-element blob), and the 
package's tests give the same result as on main: `[ FAIL 0 | WARN 0 | SKIP 62 | 
PASS 1397 ]`, with arrow not installed. The method must not pass `.from_c` on: 
a variant that forwards `...` still fails on the data frame, with "Package 
'arrow' required for create binary array from object of type list". I'm happy 
to open a PR with a test.
   


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