Skip to content

Commit

Permalink
[r] Use .Deprecated for used_shape in R (#2835)
Browse files Browse the repository at this point in the history
* [r] Use `.Deprecated` for `used_shape` in R

* code-review feedback

Co-authored-by: Dirk Eddelbuettel <[email protected]>

* Suppress warnings in tests to prevent weird testthat output

---------

Co-authored-by: Dirk Eddelbuettel <[email protected]>
Co-authored-by: Paul Hoffman <[email protected]>
  • Loading branch information
3 people authored Aug 5, 2024
1 parent 76c16fd commit edabcb6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions apis/r/R/TileDBArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ TileDBArray <- R6::R6Class(
isTRUE(simplify) || isFALSE(simplify),
isTRUE(index1) || isFALSE(index1)
)
.Deprecated(new="shape", msg="The 'used_shape' function will be removed in TileDB-SOMA 1.14.")
dims <- self$dimnames()
utilized <- vector(mode = 'list', length = length(dims))
names(utilized) <- dims
Expand Down
41 changes: 32 additions & 9 deletions apis/r/tests/testthat/test-SOMASparseNDArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,23 +416,32 @@ test_that("SOMASparseNDArray bounding box", {
}
}

expect_type(bbox <- ndarray$used_shape(index1 = TRUE), 'list')
expect_type(
bbox <- suppressWarnings(ndarray$used_shape(index1 = TRUE), classes = "deprecatedWarning"),
'list'
)
expect_length(bbox, length(dim(mat)))
expect_equal(names(bbox), dnames)
expect_true(all(vapply(bbox, length, integer(1L)) == 2L))
for (i in seq_along(bbox)) {
expect_equal(bbox[[i]], bit64::as.integer64(c(1L, dim(mat)[i])))
}

expect_type(bbox0 <- ndarray$used_shape(index1 = FALSE), 'list')
expect_type(
bbox0 <- suppressWarnings(ndarray$used_shape(index1 = FALSE), classes = "deprecatedWarning"),
'list'
)
expect_length(bbox0, length(dim(mat)))
expect_equal(names(bbox0), dnames)
expect_true(all(vapply(bbox0, length, integer(1L)) == 2L))
for (i in seq_along(bbox0)) {
expect_equal(bbox0[[i]], bit64::as.integer64(c(0L, dim(mat)[i] - 1L)))
}

expect_s3_class(bboxS <- ndarray$used_shape(simplify = TRUE), 'integer64')
expect_s3_class(
bboxS <- suppressWarnings(ndarray$used_shape(simplify = TRUE), classes = "deprecatedWarning"),
'integer64'
)
expect_length(bboxS, length(dim(mat)))
expect_equal(names(bboxS), dnames)
for (i in seq_along(bboxS)) {
Expand All @@ -459,7 +468,7 @@ test_that("SOMASparseNDArray without bounding box", {

expect_false(all(bbox_names %in% names(tiledb::tiledb_get_all_metadata(ndarray$object))))

expect_error(ndarray$used_shape())
expect_error(suppressWarnings(ndarray$used_shape(), classes = "deprecatedWarning"))
})

test_that("SOMASparseNDArray with failed bounding box", {
Expand Down Expand Up @@ -489,7 +498,7 @@ test_that("SOMASparseNDArray with failed bounding box", {

expect_false(all(bbox_names %in% names(tiledb::tiledb_get_all_metadata(ndarray$object))))

expect_error(ndarray$used_shape())
expect_error(suppressWarnings(ndarray$used_shape(), classes = "deprecatedWarning"))
})

test_that("SOMASparseNDArray bounding box implicitly-stored values", {
Expand Down Expand Up @@ -521,23 +530,32 @@ test_that("SOMASparseNDArray bounding box implicitly-stored values", {
}
}

expect_type(bbox <- ndarray$used_shape(index1 = TRUE), 'list')
expect_type(
bbox <- suppressWarnings(ndarray$used_shape(index1 = TRUE), classes = "deprecatedWarning"),
'list'
)
expect_length(bbox, length(dim(mat)))
expect_equal(names(bbox), dnames)
expect_true(all(vapply(bbox, length, integer(1L)) == 2L))
for (i in seq_along(bbox)) {
expect_equal(bbox[[i]], bit64::as.integer64(c(1L, dim(mat)[i])))
}

expect_type(bbox0 <- ndarray$used_shape(index1 = FALSE), 'list')
expect_type(
bbox0 <- suppressWarnings(ndarray$used_shape(index1 = FALSE), classes = "deprecatedWarning"),
'list'
)
expect_length(bbox0, length(dim(mat)))
expect_equal(names(bbox0), dnames)
expect_true(all(vapply(bbox0, length, integer(1L)) == 2L))
for (i in seq_along(bbox0)) {
expect_equal(bbox0[[i]], bit64::as.integer64(c(0L, dim(mat)[i] - 1L)))
}

expect_s3_class(bboxS <- ndarray$used_shape(simplify = TRUE), 'integer64')
expect_s3_class(
bboxS <- suppressWarnings(ndarray$used_shape(simplify = TRUE), classes = "deprecatedWarning"),
'integer64'
)
expect_length(bboxS, length(dim(mat)))
expect_equal(names(bboxS), dnames)
for (i in seq_along(bboxS)) {
Expand All @@ -551,7 +569,12 @@ test_that("SOMASparseNDArray bounding box implicitly-stored values", {
ranges[i] <- bit64::as.integer64(max(range(slot(mat, s))))
}
expect_equal(ndarray$non_empty_domain(), ranges)
expect_true(all(ndarray$non_empty_domain() < ndarray$used_shape(simplify = TRUE)))
expect_true(all(
ndarray$non_empty_domain() < suppressWarnings(
ndarray$used_shape(simplify = TRUE),
classes = "deprecatedWarning"
)
))
})

test_that("Bounding box assertions", {
Expand Down
5 changes: 4 additions & 1 deletion apis/r/tests/testthat/test-write-soma-resume.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ test_that("Resume-mode sparse arrays", {
expected.label = "knex"
)
bbox <- tryCatch(
as.integer(ssac$used_shape(simplify = TRUE, index1 = TRUE)),
as.integer(suppressWarnings(
ssac$used_shape(simplify = TRUE, index1 = TRUE),
classes = "deprecatedWarning"
)),
error = function(...) NULL
)
if (!is.null(bbox)) {
Expand Down

0 comments on commit edabcb6

Please sign in to comment.