Skip to content

Allow negative slices when indexing chunked data #169

@davidhassell

Description

@davidhassell

Currently (v1.0.1) negative slices, i.e. slices with a negative step, such as [10:1:-1], are not allowed on chunked data. This breaks some downstream applications (e.g. cfdm and cf-python):

>>> import pyfive
>>> q = pyfive.File('pyfive/tests/data/chunked.hdf5')
>>> q['dataset1']
<HDF5 dataset "dataset1": shape (21, 16), type "int32">
>>> q['dataset1'][::-1]
NegativeStepError: only slices with step >= 1 are supported

This can be fixed :)

Negative slices are already OK for contiguous data (because they uses np.memmap access in this case):

>>> import pyfive
>>> p = pyfive.File('pyfive/tests/data/dataset_multidim.hdf5')
>>> p['d']
<HDF5 dataset "d": shape (2, 3, 4, 5), type "int32">
>>> p['d'][::-1, 0, 0, 0]
array([60,  0], dtype=int32)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions