Skip to content

Commit

Permalink
ARROW-17543: [R] Fix bug for NULL type 0-length vectors in array crea…
Browse files Browse the repository at this point in the history
…tion

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 <[email protected]>
Signed-off-by: Nic Crane <[email protected]>
  • Loading branch information
egillax authored and thisisnic committed Aug 31, 2022
1 parent 854283d commit cf27001
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions r/R/array.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
5 changes: 5 additions & 0 deletions r/tests/testthat/test-Array.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cf27001

Please sign in to comment.