Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty tables and nullable #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/ReadH5MU.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ ReadH5MU <- function(file) {
# Metadata, features metadata, and variable features
for (modality in names(modalities)) {
# Append modality metadata
[email protected] <- cbind.data.frame([email protected], mod_obs[[modality]][obs_names,])
[email protected] <- cbind.data.frame([email protected], mod_obs[[modality]][obs_names,,drop=FALSE])

metafeatures <- srt[[modality]]@meta.features

Expand Down
27 changes: 23 additions & 4 deletions R/ReadUtils.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ read_table_encv1 <- function(dataset, set_index = TRUE) {
columns <- columns[columns != "__categories"]

col_list <- lapply(columns, function(name) {
values <- dataset[[name]]$read()
if (dataset[[name]]$dims == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps add a comment referencing hhoeflin/hdf5r#118 so we know what this workaround is for (and can remove it in the future)

values <- list()
} else {
values <- dataset[[name]]$read()
}
values_attr <- tryCatch({
h5attributes(dataset[[name]])
}, error = function(e) {
Expand All @@ -59,7 +63,13 @@ read_table_encv1 <- function(dataset, set_index = TRUE) {
}
values
})
table <- data.frame(Reduce(cbind.data.frame, col_list))
empty_columns <- vapply(col_list, function(e) { length(e) == 0 }, c(TRUE))
if (all(empty_columns)) {
# no rows
table <- data.frame(matrix(ncol = length(columns), nrow = 0))
} else {
table <- data.frame(Reduce(cbind.data.frame, col_list), drop=FALSE)
}
colnames(table) <- columns
table
}
Expand All @@ -77,13 +87,22 @@ read_column <- function(column, etype, eversion) {

values <- factor(as.integer(codes), labels = categories[1:length(codes_notna)])
} else {
warning(paste0("Cannot recognise encoving-version ", eversion))
warning(paste0("Cannot recognise encoding-version ", eversion))
}
} else if (etype == "nullable-integer" || etype == "nullable-boolean") {
# https://anndata.readthedocs.io/en/latest/fileformat-prose.html#nullable-integers-and-booleans
if (eversion == "0.1.0") {
values <- column[["values"]]$read()
mask <- column[["mask"]]$read()
values[mask] <- NA
} else {
warning(paste0("Cannot recognise encoding-version ", eversion))
}
} else {
values <- column$read()
}
# } else {
# stop(paste0("Cannot recognise encoving-type ", etype))
# stop(paste0("Cannot recognise encoding-type ", etype))
# }
values
}
Expand Down
Loading