diff --git a/versioned_hdf5/backend.py b/versioned_hdf5/backend.py index 53e70de3..ab883ac6 100644 --- a/versioned_hdf5/backend.py +++ b/versioned_hdf5/backend.py @@ -1323,7 +1323,7 @@ def write_to_dataset( written by this function. """ raw_data: Dataset = f["_version_data"][name]["raw_data"] - chunk_size = tuple(raw_data.attrs["chunks"])[0] + chunk_size = raw_data.chunks[0] if isinstance(data, np.ndarray) and raw_data.dtype != data.dtype: raise ValueError( @@ -1334,8 +1334,8 @@ def write_to_dataset( slices: Dict[Tuple, Tuple] = {} with Hashtable(f, name) as hashtable: for data_slice, vchunk in zip( - partition(data, chunk_size), - partition(virtual_slice, chunk_size), + partition(data, raw_data.chunks), + partition(virtual_slice, raw_data.chunks), strict=True, ): arr = data[data_slice.raw] diff --git a/versioned_hdf5/slicetools.py b/versioned_hdf5/slicetools.py index d0791885..f26d9bf3 100644 --- a/versioned_hdf5/slicetools.py +++ b/versioned_hdf5/slicetools.py @@ -90,7 +90,7 @@ def overlap(index1: Slice, index2: Slice) -> Optional[Slice]: overlapping = Slice(max(index1.start, index2.start), min(index1.stop, index2.stop)) # If the slices don't overlap, the start index will be greater than # the stop index - if overlapping.start > overlapping.stop: + if overlapping.start >= overlapping.stop: return None return overlapping diff --git a/versioned_hdf5/tests/test_backend.py b/versioned_hdf5/tests/test_backend.py index 012cd158..560acf29 100644 --- a/versioned_hdf5/tests/test_backend.py +++ b/versioned_hdf5/tests/test_backend.py @@ -10,6 +10,7 @@ DEFAULT_CHUNK_SIZE, create_base_dataset, create_virtual_dataset, + overlap_tuple, write_dataset, write_dataset_chunks, ) @@ -800,3 +801,12 @@ def test_create_empty_virtual_dataset(setup_vfile): assert_equal(ds, np.array([])) assert ds.shape == (0,) assert ds.size == 0 + + +def test_overlap_tuple(): + """Test that multidimensional indices which don't overlap have no overlap_tuple.""" + overlapping = overlap_tuple( + Tuple(slice(0, 3, 1), slice(15100, 15200, 1), slice(0, 2, 1)), + Tuple(slice(0, 2, 1), slice(15200, 15220, 1), slice(0, 2, 1)), + ) + assert overlapping is None