Closed bertcoerver closed 1 year ago
You are reading an HDF5 file that may have been compressed with szip. https://github.com/conda-forge/hdf5-feedstock/pull/179 should fix that but for now we do not support that filter
I have a similar issue (same error message) with the latest 2 versions of netCDF4 from conda-forge (v1.6.2
and v1.6.3
) when writing string variables to a netcdf file.
Creating a conda environment via conda create -c conda-forge -n nc python=3.10 netCDF4=1.6.3
and then running the following python script
from netCDF4 import Dataset
import numpy as np
with Dataset('/tmp/test.nc', 'w') as nc:
nc.createDimension('loc', 3)
dat = nc.createVariable('var1', str, ('loc',), zlib=True)
dat[:] = np.array(['one', 'two', 'three'])
raises an error RuntimeError: NetCDF: Filter error: bad id or parameters or duplicate filter
.
The same script works fine with netcdf4<=1.6.1
from conda-forge, and it also works fine when I set zlib=False
for the latest 2 versions . But the new versions from the defaults channel (i.e. 1.6.2 and 1.6.3) always work fine (even with zlib=True
) so I assume this is not intended behavior of the conda-forge version of the package.
For now I use netCDF4 from defaults as a workaround.
@dopplershift, any insight into this? Or suggestions for who to check with? Are we not configuring something correctly here?
You can't apply compression to string variables. This never worked, but was made a hard error by recent netcdf-c releases. See this discussion for more info.
Nothing for us to do here, so closing.
Thanks @dopplershift, that's helpful. Odd that the version from defaults isn't showing this error. That actually seems like a problem with the version on defaults.
@xylar That's easy: defaults is on 4.8.1, the PR that made the change, Unidata/netcdf-c#2231, wasn't released until netcdf-c (libnetcdf
) 4.9.0.
Ah, I see. So nothing to do with the version of netcdf4
.
Thanks for clarifying
Solution to issue cannot be found in the documentation.
Issue
When I install
netcdf4
usingconda
, I'm unable to open certain datasets, while when usingpip
to installnetcdf4
, they do open. According to people over at netcdf4-python (see issue #1182), this is because the binary wheels have support for the optional szip compression filter, while apparently the conda package does not. Although szip has a restrictive license on re-distribution, the binary wheels uselibaec
which is a drop-in replacement for szip with better licensing.Creating a new conda environment using:
and then running the following code in Python:
I get the following error (I can see the metadata of the file, it's just the opening of the actual data with [...] that causes the error):
When I create a conda environment like this:
The code works fine.
Installed packages
Environment info