Skip to content

Commit

Permalink
fix: Complete test coverage and fix errors (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot authored Jan 1, 2024
1 parent eac4875 commit 92eee09
Show file tree
Hide file tree
Showing 20 changed files with 435 additions and 76 deletions.
1 change: 1 addition & 0 deletions .covrignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ src/geoarrow.h
src/fast_float.h
src/d2s.c
src/ryu
src/double_parse_fast_float.cc
22 changes: 7 additions & 15 deletions R/array.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@ as_geoarrow_array_stream.nanoarrow_array_stream <- function(x, ..., schema = NUL
geoarrow_array_from_buffers <- function(schema, buffers) {
schema <- nanoarrow::as_nanoarrow_schema(schema)
extension_name <- schema$metadata[["ARROW:extension:name"]]
if (is.null(extension_name)) {
stop("Expected extension name")
}
stopifnot(!is.null(extension_name))

switch(
extension_name,
Expand Down Expand Up @@ -222,14 +220,8 @@ nested_array_from_buffers <- function(schema, buffers, level, validity = NULL) {
validity <- as_validity_buffer(validity)

array <- nanoarrow::nanoarrow_array_init(schema)

if (identical(schema$format, "+l")) {
offsets <- as_offset_buffer(buffers[[1]])
offset_element_size <- 4L
} else {
offsets <- as_large_offset_buffer(buffers[[1]])
offset_element_size <- 8L
}
offsets <- as_offset_buffer(buffers[[1]])
offset_element_size <- 4L

if (offsets$size_bytes == 0) {
return(array)
Expand Down Expand Up @@ -295,25 +287,25 @@ as_large_offset_buffer <- function(x) {

as_validity_buffer <- function(x) {
if (is.null(x)) {
return(list(null_count = 0, buffer = NULL))
return(list(null_count = 0L, buffer = NULL))
}

if (inherits(x, "nanoarrow_buffer")) {
return(list(null_count = -1, buffer = x))
return(list(null_count = -1L, buffer = x))
}

if (is.logical(x)) {
null_count <- sum(!x)
} else {
null_count <- sum(x == 0)
null_count <- sum(x == 0L)
}

array <- nanoarrow::as_nanoarrow_array(x, schema = nanoarrow::na_bool())
if (array$null_count > 0) {
stop("NA values are not allowed in validity buffer")
}

list(null_count == null_count, buffer = x$buffers[[2]])
list(null_count = null_count, buffer = array$buffers[[2]])
}

# This really needs a helper in nanoarrow, but for now, we need a way to drop
Expand Down
8 changes: 2 additions & 6 deletions R/kernel.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ geoarrow_kernel <- function(kernel_name, input_types, options = NULL) {
}

geoarrow_kernel_push <- function(kernel, args) {
if (!inherits(kernel, "geoarrow_kernel")) {
stop("kernel must inherit from 'geoarrow_kernel'")
}
stopifnot(inherits(kernel, "geoarrow_kernel"))

if (isTRUE(attr(kernel, "is_agg"))) {
array_out <- NULL
Expand All @@ -91,9 +89,7 @@ geoarrow_kernel_push <- function(kernel, args) {

args <- lapply(args, nanoarrow::as_nanoarrow_array)
expected_arg_count <- length(attr(kernel, "input_types"))
if (length(args) != expected_arg_count) {
stop(sprintf("Expected %d arguments but got %d", expected_arg_count, length(args)))
}
stopifnot(length(args) == expected_arg_count)

.Call(geoarrow_c_kernel_push, kernel, args, array_out)
array_out
Expand Down
File renamed without changes.
11 changes: 10 additions & 1 deletion R/nanoarrow-compat.R → R/pkg-nanoarrow.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@

# Runs before coverage starts on load
# nocov start
register_geoarrow_extension <- function() {
for (ext_name in geoarrow_extension_name_all()) {
all_ext_name <- c(
"geoarrow.wkt", "geoarrow.wkb", "geoarrow.point", "geoarrow.linestring",
"geoarrow.polygon", "geoarrow.multipoint", "geoarrow.mutlilinestring",
"geoarrow.multipolygon"
)

for (ext_name in all_ext_name) {
nanoarrow::register_nanoarrow_extension(
ext_name,
nanoarrow::nanoarrow_extension_spec(subclass = "geoarrow_extension_spec")
)
}
}
# nocov end

#' @importFrom nanoarrow infer_nanoarrow_ptype_extension
#' @export
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions R/type.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ na_extension_geoarrow <- function(geometry_type, dimensions = "XY",
na_extension_geoarrow_internal(type_id, crs = crs, edges = edges)
}

geoarrow_extension_name_all <- function() {
c("geoarrow.wkt", "geoarrow.wkb", "geoarrow.point", "geoarrow.linestring",
"geoarrow.polygon", "geoarrow.multipoint", "geoarrow.mutlilinestring",
"geoarrow.multipolygon")
}

#' Inspect a GeoArrow schema
#'
#' @param schema A [nanoarrow_schema][nanoarrow::as_nanoarrow_schema]
Expand Down
2 changes: 1 addition & 1 deletion src/r-vctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SEXP geoarrow_c_vctr_chunk_offsets(SEXP array_list) {
array = (struct ArrowArray*)R_ExternalPtrAddr(VECTOR_ELT(array_list, i));
cumulative_offset += array->length;
if (cumulative_offset > INT_MAX) {
Rf_error("Can't build geoarrow_vctr with length > INT_MAX");
Rf_error("Can't build geoarrow_vctr with length > INT_MAX"); // # nocov
}

offsets[i + 1] = cumulative_offset;
Expand Down
Loading

0 comments on commit 92eee09

Please sign in to comment.