Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the new compression argument in netCDF4 > 1.6.0 #6981

Merged
merged 12 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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