Skip to content
forked from pydata/xarray

Commit

Permalink
Support the new compression argument in netCDF4 > 1.6.0 (pydata#6981)
Browse files Browse the repository at this point in the history
* Added support for the new compression argument in netCDF4 > 1.6.0

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Check both netCDF4 and libnetcdf versions to see if they support the new
compression arguments.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove checking netCDF4 and libnetcdf versions. We let them fail if they do not match compression/zlib arguments.

* Added test after merging with the new version of the file.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Deepak Cherian <dcherian@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 1, 2022
1 parent 88e1aea commit 92e7cb5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion xarray/backends/netCDF4_.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ def _extract_nc4_variable_encoding(
"shuffle",
"_FillValue",
"dtype",
"compression",
}
if lsd_okay:
valid_encodings.add("least_significant_digit")
if h5py_okay:
valid_encodings.add("compression")
valid_encodings.add("compression_opts")

if not raise_on_invalid and encoding.get("chunksizes") is not None:
Expand Down
6 changes: 6 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -5068,6 +5068,12 @@ def test_extract_nc4_variable_encoding(self) -> None:
encoding = _extract_nc4_variable_encoding(var, unlimited_dims=("x",))
assert {} == encoding

@requires_netCDF4
def test_extract_nc4_variable_encoding_netcdf4(self, monkeypatch):
# New netCDF4 1.6.0 compression argument.
var = xr.Variable(("x",), [1, 2, 3], {}, {"compression": "szlib"})
_extract_nc4_variable_encoding(var, backend="netCDF4", raise_on_invalid=True)

def test_extract_h5nc_encoding(self) -> None:
# not supported with h5netcdf (yet)
var = xr.Variable(("x",), [1, 2, 3], {}, {"least_sigificant_digit": 2})
Expand Down

0 comments on commit 92e7cb5

Please sign in to comment.