Skip to content

Commit

Permalink
retrieving maxshape from dataobjects and exposing maxshape property o…
Browse files Browse the repository at this point in the history
…n Dataset
  • Loading branch information
bmaranville committed Feb 22, 2024
1 parent d21662e commit 011dedd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pyfive/dataobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,16 @@ def shape(self):
""" Shape of the dataset. """
msg = self.find_msg_type(DATASPACE_MSG_TYPE)[0]
msg_offset = msg['offset_to_message']
return determine_data_shape(self.msg_data, msg_offset)
shape, maxshape = determine_data_shape(self.msg_data, msg_offset)
return shape

@property
def maxshape(self):
""" Maximum Shape of the dataset. (None for unlimited dimension) """
msg = self.find_msg_type(DATASPACE_MSG_TYPE)[0]
msg_offset = msg['offset_to_message']
shape, maxshape = determine_data_shape(self.msg_data, msg_offset)
return maxshape

@property
def fillvalue(self):
Expand Down Expand Up @@ -648,6 +657,8 @@ def is_dataset(self):
""" True when DataObjects points to a dataset, False for a group. """
return len(self.find_msg_type(DATASPACE_MSG_TYPE)) > 0

UNLIMITED_SIZE = struct.unpack('<Q', b'\xff\xff\xff\xff\xff\xff\xff\xff')[0]


def determine_data_shape(buf, offset):
""" Return the shape of the dataset pointed to in a Dataspace message. """
Expand All @@ -665,9 +676,15 @@ def determine_data_shape(buf, offset):

ndims = header['dimensionality']
dim_sizes = struct.unpack_from('<' + 'Q' * ndims, buf, offset)
offset += 8 * ndims
# Dimension maximum size follows if header['flags'] bit 0 set
if header['flags'] & 2**0:
maxshape = struct.unpack_from('<' + 'Q' * ndims, buf, offset)
maxshape = tuple((None if d == UNLIMITED_SIZE else d) for d in maxshape)
else:
maxshape = dim_sizes
# Permutation index follows if header['flags'] bit 1 set
return dim_sizes
return dim_sizes, maxshape


# HDF5 Structures
Expand Down
5 changes: 5 additions & 0 deletions pyfive/high_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ def shape(self):
""" shape attribute. """
return self._dataobjects.shape

@property
def maxshape(self):
""" maxshape attribute. (None for unlimited dimensions) """
return self._dataobjects.maxshape

@property
def ndim(self):
""" number of dimensions. """
Expand Down

0 comments on commit 011dedd

Please sign in to comment.