Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve maxshape for Dataset #56

Merged
merged 2 commits into from
Feb 28, 2024
Merged
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
24 changes: 21 additions & 3 deletions pyfive/dataobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from .btree import GZIP_DEFLATE_FILTER, SHUFFLE_FILTER, FLETCH32_FILTER
from .misc_low_level import Heap, SymbolTable, GlobalHeap, FractalHeap

# these constants happen to have the same value...
UNLIMITED_SIZE = UNDEFINED_ADDRESS


class DataObjects(object):
"""
Expand Down Expand Up @@ -180,7 +183,7 @@ def unpack_attribute(self, offset):
offset += _padded_size(attr_dict['datatype_size'], padding_multiple)

# read in the dataspace information
shape = determine_data_shape(self.msg_data, offset)
shape, maxshape = determine_data_shape(self.msg_data, offset)
items = int(np.product(shape))
offset += _padded_size(attr_dict['dataspace_size'], padding_multiple)

Expand Down Expand Up @@ -246,7 +249,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 @@ -665,9 +677,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
Loading