diff --git a/xarray/backends/netCDF4_.py b/xarray/backends/netCDF4_.py index 7b37b1a573a..f8b3192a4b9 100644 --- a/xarray/backends/netCDF4_.py +++ b/xarray/backends/netCDF4_.py @@ -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: diff --git a/xarray/tests/test_backends.py b/xarray/tests/test_backends.py index a477aea9d62..81417f8a06a 100644 --- a/xarray/tests/test_backends.py +++ b/xarray/tests/test_backends.py @@ -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})