Skip to content

Commit

Permalink
fix(memh5): block axis downselection in shared datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
ljgray committed Apr 25, 2023
1 parent b914bc3 commit 714b167
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions caput/memh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,9 @@ def deep_group_copy(
>>> list(g2["foo"]["bar"])
[0, 1]
It is important to note that axis downselections cannot be applied to
shared datasets.
Parameters
----------
g1 : h5py.Group or zarr.Group
Expand Down Expand Up @@ -2590,10 +2593,9 @@ def deep_group_copy(

to_file = isinstance(g2, file_format.module.Group)

# Prepare a dataset for writing out, applying selections and transforming any
# datatypes
# Returns: dict(dtype, shape, data_to_write)
def _prepare_dataset(dset):
# Get the selection associated with this dataset
# Returns: slice
def _get_selection(dset):
# Look for a selection for this dataset (also try without the leading "/")
try:
selection = selections.get(
Expand All @@ -2602,6 +2604,14 @@ def _prepare_dataset(dset):
except AttributeError:
selection = slice(None)

return selection

# Prepare a dataset for writing out, applying selections and transforming any
# datatypes
# Returns: dict(dtype, shape, data_to_write)
def _prepare_dataset(dset):
selection = _get_selection(dset)

# Check if this is a distributed dataset and figure out if we can make this work
# out
if to_file and isinstance(dset, MemDatasetDistributed):
Expand Down Expand Up @@ -2708,6 +2718,11 @@ def _prepare_compression_args(dset):
stack += [entry[k] for k in sorted(entry, reverse=True)]

elif key in shared:
# Make sure that we aren't trying to apply a selection to this dataset
if _get_selection(entry) != slice(None):
raise ValueError(
f"Cannot apply a selection to a shared dataset ({entry.name})"
)
# Just point to the existing dataset
parent_name, name = posixpath.split(posixpath.join(g2.name, key))
parent_name = format_abs_path(parent_name)
Expand Down

0 comments on commit 714b167

Please sign in to comment.