Skip to content

HDF Error when attempting to create variable defined with compound under some conditions #1270

@smndvgnc

Description

@smndvgnc
import netCDF4
import numpy as np


filt_shape = (8192)
n_filt = 1

with netCDF4.Dataset("my_netcdf.nc", "w") as ds:
    filter_defn = np.dtype(
        [
            ("filter", np.float64, filt_shape),
        ]
    )

    filter_type = ds.createCompoundType(filter_defn, "filters")

    index_dim = ds.createDimension("index", n_filt)

    v = ds.createVariable("filter_list", filter_type, index_dim)

The above code does not work and crashes with the following error:

Traceback (most recent call last):
  File "/Users/smndvgnc/Downloads/test_nc.py", line 8, in <module>
    with netCDF4.Dataset("my_netcdf.nc", "w") as ds:
  File "src/netCDF4/_netCDF4.pyx", line 2498, in netCDF4._netCDF4.Dataset.__exit__
  File "src/netCDF4/_netCDF4.pyx", line 2622, in netCDF4._netCDF4.Dataset.close
  File "src/netCDF4/_netCDF4.pyx", line 2585, in netCDF4._netCDF4.Dataset._close
  File "src/netCDF4/_netCDF4.pyx", line 2029, in netCDF4._netCDF4._ensure_nc_success
RuntimeError: NetCDF: HDF error

If you change filt_shape to (8191), the problem vanishes. This issue appeared with version 1.6.2. Version 1.6.1 does not produce error using the code snippet.

To spare you some calculations:
8191 elements in double precision: 65528 bytes
8192 elements in double precision: 65536 bytes (=2**16).

A size above 8192 also makes it crash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions