Closed paleolimbot closed 1 month ago
Attention: Patch coverage is 97.20280%
with 8 lines
in your changes are missing coverage. Please review.
Project coverage is 89.09%. Comparing base (
9935713
) to head (6aefdd2
). Report is 39 commits behind head on main.
Files | Patch % | Lines |
---|---|---|
r/R/vctr.R | 96.29% | 5 Missing :warning: |
r/src/convert_array_stream.c | 91.30% | 2 Missing :warning: |
r/src/materialize.c | 98.11% | 1 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Amazing work, great to see these changes rolling in in real time!
This PR adds the
nanoarrow_vctr
, which is an R translation of the PythonArray
class in nanoarrow's Python bindings. This is implemented like an Rfactor()
in the sense that under the hood it is a sequence of integers (0:(array$length - 1)
at the beginning) with attributes that give those integers context.This is implemented in such a way that it is "tacked on" to the existing conversions. The existing conversions do need a refactoring ( https://github.com/apache/arrow-nanoarrow/pull/392 ), but that is a heavy change for this point in the release cycle.
The only change needed to the existing conversion was a slight refactor of the "consume array stream" code that correctly gave each array in the stream its own R object to manage its lifecycle (before each array was "materialized" and then immediately released because no previous conversion code required an ArrowArray to live beyond the conversion.
The motivation for this change is converting GeoArrow extension types. In the geoarrow package, we implement an efficient conversion from a stream of arrays to various types of R-spatial objects (e.g., sf); however, we really don't want to invoke the default conversion for those types because they have awful performance (e.g., the multipolygon would be a
list(list(list(data.frame))))
) and there's no need to invoke that number of R object conversions between the initial state (an arrow array) and the final state (an sfc column). The nanoarrow_vctr allows something like:A side-effect of this change is that we have an escape hatch for conversions that are lossy or contain types with no R equivalent.
A quick demo:
Created on 2024-05-10 with reprex v2.1.0