From 88f85577ea53f8bb78f850ece964b1cd7b0b45bc Mon Sep 17 00:00:00 2001 From: LTLA Date: Mon, 27 Nov 2023 23:10:38 -0800 Subject: [PATCH] Bugfix for correct dimnames reading in dense arrays. Also extended tests for arrays inside DFs to the new world. --- R/readArray.R | 2 +- tests/testthat/test-stage-df.R | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/R/readArray.R b/R/readArray.R index 9e92952..50a4fa5 100644 --- a/R/readArray.R +++ b/R/readArray.R @@ -44,7 +44,7 @@ readArray <- function(path, array.file.backed=TRUE, ...) { on.exit(H5Dclose(dhandle), add=TRUE, after=FALSE) placeholder <- h5_read_attribute(dhandle, "missing-value-placeholder", check=TRUE, default=NULL) - ndims <- length(H5Sget_simple_extent_dims(H5Dget_space(dhandle))) + ndims <- H5Sget_simple_extent_dims(H5Dget_space(dhandle))$rank names <- load_names(ghandle, ndims) list(type=type, names=names, transposed=(transposed != 0L), placeholder=placeholder) diff --git a/tests/testthat/test-stage-df.R b/tests/testthat/test-stage-df.R index 4831227..4910dfb 100644 --- a/tests/testthat/test-stage-df.R +++ b/tests/testthat/test-stage-df.R @@ -19,6 +19,14 @@ test_that("staging of arrays within DFs works correctly", { roundtrip$Y <- as.matrix(roundtrip$Y) roundtrip$Z <- as.matrix(roundtrip$Z) expect_equal(roundtrip, input) + + # Works in the new world. + tmp <- tempfile() + saveObject(input, tmp) + roundtrip <- readObject(tmp) + roundtrip$Y <- as.matrix(roundtrip$Y) + roundtrip$Z <- as.matrix(roundtrip$Z) + expect_identical(roundtrip, input) }) test_that("staging of arrays continues to work with character matrices", { @@ -36,5 +44,12 @@ test_that("staging of arrays continues to work with character matrices", { roundtrip$Y <- as.matrix(roundtrip$Y) roundtrip$Z <- as.matrix(roundtrip$Z) expect_equal(roundtrip, input) -}) + # Works in the new world. + tmp <- tempfile() + saveObject(input, tmp) + roundtrip <- readObject(tmp) + roundtrip$Y <- as.matrix(roundtrip$Y) + roundtrip$Z <- as.matrix(roundtrip$Z) + expect_identical(roundtrip, input) +})