Skip to content

Issue loading file due to buffer too small #100

@valeriupredoi

Description

@valeriupredoi

Here is the MRE:

import pyfive


def _load_nc_file(ncvar):
    """
    Get the netcdf file and its b-tree.

    Fixture to test loading an issue file.
    """
    issue_file = "da193a_25_6hr_t_pt_cordex__198807-198807.nc"
    nc = pyfive.File(issue_file)
    ds = nc[ncvar]

    return ds


def test_buffer_issue():
    print("File issue: da193a_25_6hr_t_pt_cordex__198807-198807.nc")
    print("Variable m01s30i111")
    _load_nc_file('m01s30i111')

test_buffer_issue()

this instantly returns the barf:

$ python test_buffer_local.py
File issue: da193a_25_6hr_t_pt_cordex__198807-198807.nc
Variable m01s30i111
Traceback (most recent call last):
  File "/home/valeriu/test_buffer_local.py", line 22, in <module>
    test_buffer_issue()
    ~~~~~~~~~~~~~~~~~^^
  File "/home/valeriu/test_buffer_local.py", line 20, in test_buffer_issue
    _load_nc_file('m01s30i111')
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/home/valeriu/test_buffer_local.py", line 12, in _load_nc_file
    ds = nc[ncvar]
         ~~^^^^^^^
  File "/home/valeriu/miniconda3/envs/pyactive4/lib/python3.13/site-packages/pyfive/high_level.py", line 94, in __getitem__
    return Dataset(obj_name, DatasetID(dataobjs), self)
                             ~~~~~~~~~^^^^^^^^^^
  File "/home/valeriu/miniconda3/envs/pyactive4/lib/python3.13/site-packages/pyfive/h5d.py", line 93, in __init__
    self._meta = DatasetMeta(dataobject)
                 ~~~~~~~~~~~^^^^^^^^^^^^
  File "/home/valeriu/miniconda3/envs/pyactive4/lib/python3.13/site-packages/pyfive/h5d.py", line 593, in __init__
    self.attributes = dataobject.get_attributes()
                      ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/valeriu/miniconda3/envs/pyactive4/lib/python3.13/site-packages/pyfive/dataobjects.py", line 154, in get_attributes
    more_attrs = self._get_attributes_from_attr_info(attrs, attr_info)
  File "/home/valeriu/miniconda3/envs/pyactive4/lib/python3.13/site-packages/pyfive/dataobjects.py", line 180, in _get_attributes_from_attr_info
    name, value = self._parse_attribute_msg(data,0)
                  ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/valeriu/miniconda3/envs/pyactive4/lib/python3.13/site-packages/pyfive/dataobjects.py", line 237, in _parse_attribute_msg
    value = self._attr_value(dtype, buffer, items, offset)
  File "/home/valeriu/miniconda3/envs/pyactive4/lib/python3.13/site-packages/pyfive/dataobjects.py", line 273, in _attr_value
    value = np.frombuffer(buf, dtype=dtype, count=count, offset=offset)
ValueError: buffer is smaller than requested size

This is run locally on POSIX, but in #99 the same behaviour occurs for the same file but on an S3 FS, accessed via s3fs. This has to be something specific to the file, I will investigate more, and will post updates below, in the comments.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions