8000 Support the new compression argument in netCDF4 > 1.6.0 (#6981) · pydata/xarray@92e7cb5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 92e7cb5

Browse files
markelgpre-commit-ci[bot]dcherian
authored
Support the new compression argument in netCDF4 > 1.6.0 (#6981)
* 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>
1 parent 88e1aea commit 92e7cb5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

xarray/backends/netCDF4_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,11 @@ def _extract_nc4_variable_encoding(
232232
"shuffle",
233233
"_FillValue",
234234
"dtype",
235+
"compression",
235236
}
236237
if lsd_okay:
237238
valid_encodings.add("least_significant_digit")
238239
if h5py_okay:
239-
valid_encodings.add("compression")
240240
valid_encodings.add("compression_opts")
241241

242242
if not raise_on_invalid and encoding.get("chunksizes") is not None:

xarray/tests/test_backends.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5068,6 +5068,12 @@ def test_extract_nc4_variable_encoding(self) -> None:
50685068
encoding = _extract_nc4_variable_encoding(var, unlimited_dims=("x",))
50695069
assert {} == encoding
50705070

5071+
@requires_netCDF4
5072+
def test_extract_nc4_variable_encoding_netcdf4(self, monkeypatch):
5073+
# New netCDF4 1.6.0 compression argument.
5074+
var = xr.Variable(("x",), [1, 2, 3], {}, {"compression": "szlib"})
5075+
_extract_nc4_variable_encoding(var, backend="netCDF4", raise_on_invalid=True)
5076+
50715077
def test_extract_h5nc_encoding(self) -> None:
50725078
# not supported with h5netcdf (yet)
50735079
var = xr.Variable(("x",), [1, 2, 3], {}, {"least_sigificant_digit": 2})

0 commit comments

Comments
 (0)
0