You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by th...@apache.org on 2022/08/31 08:29:59 UTC

[arrow] branch master updated: ARROW-17543: [R] Fix bug for NULL type 0-length vectors in array creation

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

thisisnic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new cf27001da0 ARROW-17543: [R] Fix bug for NULL type 0-length vectors in array creation
cf27001da0 is described below

commit cf27001da088d882a7d460cddd84a0202f3d8eba
Author: Egill Fridgeirsson <eg...@gmail.com>
AuthorDate: Wed Aug 31 09:29:49 2022 +0100

    ARROW-17543: [R] Fix bug for NULL type 0-length vectors in array creation
    
    Added the suggested check in ```Array$create()``` from the JIRA issue, that if both the ```x``` and ```type``` are ```NULL``` then the type is manually assigned to ```arrow::null()```.
    
    Added unit tests that captured the bug before I applied the fix and now pass.
    
    Closes #13990 from egillax/detect_and_fix_type_null_vectors
    
    Authored-by: Egill Fridgeirsson <eg...@gmail.com>
    Signed-off-by: Nic Crane <th...@gmail.com>
---
 r/R/array.R                   | 3 +++
 r/tests/testthat/test-Array.R | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/r/R/array.R b/r/R/array.R
index 9ae7631e7d..edee417ea1 100644
--- a/r/R/array.R
+++ b/r/R/array.R
@@ -176,6 +176,9 @@ Array$create <- function(x, type = NULL) {
   if (!is.null(type)) {
     type <- as_type(type)
   }
+  if (is.null(x) && is.null(type)) {
+    type <- null()
+  }
   if (inherits(x, "Scalar")) {
     out <- x$as_array()
     if (!is.null(type)) {
diff --git a/r/tests/testthat/test-Array.R b/r/tests/testthat/test-Array.R
index 56c7028d6a..25c844c2cc 100644
--- a/r/tests/testthat/test-Array.R
+++ b/r/tests/testthat/test-Array.R
@@ -180,6 +180,11 @@ test_that("Array support null type (ARROW-7064)", {
   expect_array_roundtrip(vctrs::unspecified(10), null())
 })
 
+test_that("Array support 0-length NULL vectors (Arrow-17543)", {
+  expect_type_equal(Array$create(c()), null())
+  expect_type_equal(Array$create(NULL), null())
+})
+
 test_that("Array supports logical vectors (ARROW-3341)", {
   # with NA
   x <- sample(c(TRUE, FALSE, NA), 1000, replace = TRUE)