Skip to content

Commit

Permalink
Fix AnnData initialisation when var is NULL (#197)
Browse files Browse the repository at this point in the history
* add test to reproduce #184

* add fix
  • Loading branch information
rcannood authored Nov 12, 2024
1 parent 3790caa commit 4f315a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ get_initial_var <- function(var, X, shape) {
if (is.null(var)) {
var <- data.frame(matrix(NA, nrow = shape[[2]], ncol = 0))
if (!is.null(X)) {
colnames(var) <- colnames(X)
rownames(var) <- colnames(X)
}
}
var
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-InMemoryAnnData.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ test_that("with empty var", {
expect_identical(ad$shape(), c(10L, 0L))
})

test_that("with only X, no obs or var", function() {
X <- dummy$X
dimnames(X) <- list(
rownames(dummy$obs),
rownames(dummy$var)
)
ad <- AnnData(X = X)
expect_identical(ad$shape(), c(10L, 20L))
expect_identical(ad$obs_names, rownames(dummy$obs))
expect_identical(ad$var_names, rownames(dummy$var))
})

# trackstatus: class=InMemoryAnnData, feature=test_get_layers, status=done
test_that("'layers' works", {
## layers test helper function
Expand Down

0 comments on commit 4f315a7

Please sign in to comment.