You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by pa...@apache.org on 2023/06/08 00:49:22 UTC

[arrow-nanoarrow] branch main updated: fix(r): Fix `convert_array_stream()` for non-record batch stream with zero batches (#212)

This is an automated email from the ASF dual-hosted git repository.

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new e9b8ad9  fix(r): Fix `convert_array_stream()` for non-record batch stream with zero batches (#212)
e9b8ad9 is described below

commit e9b8ad91279feead1dab7d1fc2b49784be5b1634
Author: Kirill Müller <kr...@users.noreply.github.com>
AuthorDate: Thu Jun 8 02:49:17 2023 +0200

    fix(r): Fix `convert_array_stream()` for non-record batch stream with zero batches (#212)
    
    Looks like a copy-pastie.
---
 r/R/convert-array-stream.R                   | 11 +++++++----
 r/tests/testthat/test-convert-array-stream.R |  3 +++
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/r/R/convert-array-stream.R b/r/R/convert-array-stream.R
index eaeda7d..c91045b 100644
--- a/r/R/convert-array-stream.R
+++ b/r/R/convert-array-stream.R
@@ -70,10 +70,13 @@ convert_array_stream <- function(array_stream, to = NULL, size = NULL, n = Inf)
     batches[[n_batches]] <- .Call(nanoarrow_c_convert_array, array, to)
   }
 
-  if (n_batches == 0L && is.data.frame(to)) {
-    to[integer(0), , drop = FALSE]
-  } else if (n_batches == 0L && is.data.frame(to)) {
-    to[integer(0)]
+  if (n_batches == 0L) {
+    # vec_slice(to, 0)
+    if (is.data.frame(to)) {
+      to[integer(0), , drop = FALSE]
+    } else {
+      to[integer(0)]
+    }
   } else if (n_batches == 1L) {
     batches[[1]]
   } else if (inherits(to, "data.frame")) {
diff --git a/r/tests/testthat/test-convert-array-stream.R b/r/tests/testthat/test-convert-array-stream.R
index 9e07124..534b91d 100644
--- a/r/tests/testthat/test-convert-array-stream.R
+++ b/r/tests/testthat/test-convert-array-stream.R
@@ -29,6 +29,9 @@ test_that("convert array stream works", {
     )
   )
   expect_identical(convert_array_stream(stream2), data.frame(x = 1:10))
+
+  stream3 <- basic_array_stream(list(), schema = na_int32())
+  expect_identical(convert_array_stream(stream3), integer())
 })
 
 test_that("convert array stream with explicit size works", {