Skip to content

Commit

Permalink
Fix bug in update_zarr_array and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
grimbough committed Oct 24, 2024
1 parent 79705b1 commit 516174f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Fixed bug when creating an empty array with a floating datatype. The fill
value would be interpreted as an integer by `read_metadata()` and create
and array of the wrong type.
* Fixed bug in `update_zarr_array()` when `NULL` was provided to one or more
dimensions in the `index` argument. This was parsed incorrectly and the
underlying zarr was not modified.
* Added support for the ZarrArray S4 class and the DelayedArray framework.
* Improvements to read and write performance.

Expand Down
1 change: 1 addition & 0 deletions R/write_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ update_zarr_array <- function(zarr_array_path, x, index) {

zarr_array_path <- .normalize_array_path(zarr_array_path)
metadata <- read_array_metadata(zarr_array_path)
index <- check_index(index, metadata = metadata)

data_type <- switch(storage.mode(x),
"integer" = "<i",
Expand Down
14 changes: 13 additions & 1 deletion inst/tinytest/test_update_zarr.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,17 @@ expect_identical( list.files(path), "0")
x <- rep(20L, 5);
expect_true(update_zarr_array(path, x = x, index = list( c(91, 93, 95, 97, 99) )))
expect_identical(read_zarr_array(path)[91:100], array(rep(c(20L, 100L), 5), dim = 10))
## only a single chunk file should have been created
## only two chunk files should have been created
expect_true( length(list.files(path)) == 2 )


## Test we can update regions where we provide NULL to the index argument for some dimensions
path <- tempfile()
res <- create_empty_zarr_array(zarr_array_path = path,
dim = c(20, 20), chunk_dim = c(10, 10), data_type = "integer",
fill_value = 0L)
x <- matrix(1:40L, ncol = 2)
index <- list(NULL, 1:2)

expect_true(update_zarr_array(path, x = x, index = index))
expect_identical(read_zarr_array(path, index = index), x)

0 comments on commit 516174f

Please sign in to comment.