Skip to content

remove extra forward slashes - #11

Open
Artur-man wants to merge 1 commit into
Bioconductor:develfrom
Artur-man:extra_slashes
Open

remove extra forward slashes#11
Artur-man wants to merge 1 commit into
Bioconductor:develfrom
Artur-man:extra_slashes

Conversation

@Artur-man

Copy link
Copy Markdown
Contributor

Hi @hpages, following @Bisaloo's suggestion I simplified group names since we have file.paths instead of paste0s now. Are these ok?

@hpages hpages left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Artur-man. See inline comments.

expect_true(is(sink, "ZarrRealizationSink"))
expect_true(is(sink, "RealizationSink"))
format <- ZarrArray:::get_zarr_format(paste0(sink@zarr_path, "/"))
format <- ZarrArray:::get_zarr_format(sink@zarr_path)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

get_zarr_format() is a thin wrapper to Rarr:::.read_array_metadata() and IIRC earlier versions of the latter required the trailing slash. Happy to get rid of it.

Comment thread R/utils.R
if (startsWith(name, "/")) {
name <- sub("^/*", "/", name) # only keep first leading slash
} else {
name <- paste0("/", name)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The purpose of normarg_zarr_group() is to normalize the supplied group, but the proposed change no longer does that. I'm open to discuss whether the normalized group should have a leading slash or not. In the current normarg_zarr_group(), the decision was made to always have a leading slash, whether the user supplied it or not. However, the proposed change no longer makes any decision with respect to the leading slash: it keeps it if the user supplied it but it doesn't add it if the user didn't. So it doesn't normalize the group anymore.

Personally I have a small preference for having the leading slash in the normalized group. This is consistent with what we do with the new group() method in HDF5Array which in turn is consistent with what they do in rhdf5::h5ls(). More generally speaking I think it's important to try to keep things as consistent as possible across HDF5Array and ZarrArray.

BTW, I'm about to add a group() method in ZarrArray that will return the normalized group of a ZarrSparseMatrixSeed or ZarrSparseMatrix object.

if (!zarr_exists(zarr_store, group))
stop(wmsg("Group \"", group, "\" does not exist in this Zarr store"))
if (zarr_node_is_dataset(zarr_store, group)) {
is_X_or_layer <- group == "/X" || startsWith(group, "/layers/")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a good example of why normalization is important. If we know that group is guaranteed to always start with a single /, then the current code does the right thing. If we know that group is guaranteed to never start with a /, then the current code no longer does the right thing but is easy to fix.
But if group sometimes has the leading slash and sometimes not, then both, the current code and the proposed change are wrong.

Additionally, the proposed change is wrong for another reason: this code tries to recognize datasets that belong to the /layers group (in which case the dataset names are going to be of the form /layers/<dataset_name> e.g. /layers/counts), but the proposed change will recognize datasets that belong to groups that start with layers (e.g. layersalt), which is not what we want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants