Skip to content

Commit

Permalink
bug fix: RuntimeError from NetCDF lib w/ zlib=True on vlens (#10)
Browse files Browse the repository at this point in the history
Avoid passing zlib=True to the NetCDF library for vlen datatypes. One
day the library decided this wasn't okay... 🤷.
  • Loading branch information
5tefan authored Jul 6, 2023
1 parent 3f4c3b8 commit d6df44b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# 0.8.16 - 2023-06-14
# 0.8.17 - 2023-07-05

- New feature: support `copy_from_alt` list of alternative variable names to use if `name` variable
isn't present.
isn't present.
- Fix bug: avoid passing `zlib=True` on str datatypes to avoid RuntimeError from NetCDF library
Unidata/netcdf4-python#1205

# 0.8.15 - 2022-11-30

Expand Down
10 changes: 8 additions & 2 deletions ncagg/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,19 @@ def initialize_aggregation_file(config, fullpath):
# fill_value is None by default, but if there is a value specified,
# explicitly cast it to the same type as the data.
fill_value = var_type.type(fill_value)
zlib = True
if np.issubdtype(var_type, str):
# NetCDF started raising RuntimeError when passed compression args on
# vlen datatypes. Detect vlens (str for now) and avoid compression.
# Ref: https://github.com/Unidata/netcdf4-python/issues/1205
zlib = False
var_out = nc_out.createVariable(
var_name,
var_type,
var["dimensions"],
chunksizes=var["chunksizes"],
zlib=True,
complevel=7,
zlib=zlib,
complevel=7 if zlib else None,
fill_value=fill_value,
)
for k, v in var["attributes"].items():
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="ncagg",
version="0.8.16",
version="0.8.17",
description="Utility for aggregation of NetCDF data.",
author="Stefan Codrescu",
author_email="stefan.codrescu@noaa.gov",
Expand All @@ -23,6 +23,7 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
Expand Down

0 comments on commit d6df44b

Please sign in to comment.