Skip to content

Commit c071098

Browse files
authored
Add check for 0 dimensions when converting to Seurat (#393)
* Add check for 0 dimensions to as_Seurat() * Add test for converting 0 dim AnnData to Seurat
1 parent d5fda31 commit c071098

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

R/as_Seurat.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ as_Seurat <- function(
145145
)
146146
}
147147

148+
if (any(dim(adata) == 0)) {
149+
cli_abort(c(
150+
paste(
151+
"{.arg adata} must have non-zero dimensions in both axes",
152+
"to be converted to a {.cls Seurat} object"
153+
),
154+
"i" = "Dimensions are: [{adata$n_obs()}, {adata$n_vars()}]"
155+
))
156+
}
157+
148158
object_metadata_mapping <- get_mapping(
149159
object_metadata_mapping,
150160
.as_Seurat_guess_object_metadata,

tests/testthat/test-as_Seurat.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,12 @@ test_that("as_Seurat works with unnamed mappings", {
179179
)
180180
)
181181
})
182+
183+
test_that("as_Seurat works with a 0 dim AnnData", {
184+
adata <- AnnData(X = as(matrix(nrow = 10, ncol = 0), "dgCMatrix"))
185+
186+
expect_error(
187+
adata$as_Seurat(layers_mapping = c(counts = NA)),
188+
"must have non-zero dimensions"
189+
)
190+
})

0 commit comments

Comments
 (0)