Skip to content
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
1 change: 1 addition & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version ?.?.?

**2026-??-??**

* Add ``__orthogonal_indexing__`` flag by `David Hassell <https://github.com/davidhassell>`_ in https://github.com/NCAS-CMS/pyfive/issue/171
* Allow negative slices when indexing chunked data by `David Hassell <https://github.com/davidhassell>`_ in https://github.com/NCAS-CMS/pyfive/pull/170

Version 1.0.1
Expand Down
32 changes: 32 additions & 0 deletions pyfive/high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pyfive.dataobjects import DataObjects, DatasetID
from pyfive.misc_low_level import SuperBlock
from pyfive.h5py import Datatype
from pyfive.p5t import P5VlenStringType, P5ReferenceType, P5SequenceType


class Group(Mapping):
Expand Down Expand Up @@ -502,6 +503,37 @@ def attrs(self):
"""attrs attribute."""
return self.id._meta.attributes

@property
def __orthogonal_indexing__(self):
"""Flag to indicate whether indexing is orthogonal.

In general, the flag will be `True` if:

* The data is chunked.
* The data is contiguous and memory mapped access is not
available.

"""
if self.id.chunks is not None:
# Chunked data indexed with
# `DatasetID._get_selection_via_chunks`
return True

if (
not (
isinstance(
self.id._ptype, (P5ReferenceType, P5VlenStringType, P5SequenceType)
)
)
and not self.id.posix
):
# Contiguous data indexed with
# `DatasetID._get_direct_from_contiguous`
return True

# All other cases
return False


class DimensionManager(Sequence):
"""Represents a collection of dimensions associated with a dataset."""
Expand Down
13 changes: 13 additions & 0 deletions tests/test_dataset_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

DIRNAME = os.path.dirname(__file__)
DATASET_CHUNKED_FILE = os.path.join(DIRNAME, "data/chunked.hdf5")
DATASET_CONTIGUOUS_FILE = os.path.join(DIRNAME, "data/dataset_multidim.hdf5")


# Define a fixture that opens the chunked file once
Expand All @@ -19,6 +20,13 @@ def chunked_file():
yield hfile


# Define a fixture that opens the contiguous file once
@pytest.fixture(scope="module")
def contiguous_file():
with pyfive.File(DATASET_CONTIGUOUS_FILE) as hfile:
yield hfile


@pytest.mark.parametrize(
"index",
[
Expand Down Expand Up @@ -65,3 +73,8 @@ def test_dataset_indexing_replace_negative_slices():
# Can't pass in in Ellipsis
with pytest.raises(ValueError) as error:
func((0, slice(6, 0, -2), ...), (7, 8, 9))


def test_dataset_orthogonal_indexing(chunked_file, contiguous_file):
assert chunked_file["dataset1"].__orthogonal_indexing__ is True
assert contiguous_file["d"].__orthogonal_indexing__ is False
Loading