Skip to content

Commit 730c138

Browse files
committed
add compression parameterization
1 parent c21547c commit 730c138

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tests/test_xarray.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import pandas as pd
55
import pytest
66
import xarray as xr
7+
from numcodecs import LZ4, Blosc, Zlib, Zstd
8+
from numcodecs.abc import Codec
79

810
import zarr
911

@@ -60,10 +62,17 @@ def dataset(
6062
return obj
6163

6264

63-
def test_roundtrip(store: zarr.abc.store.Store, dataset: xr.Dataset) -> None:
64-
dataset.to_zarr(store)
65+
@pytest.mark.parametrize("compressor", [Zstd(level=1), LZ4(), Blosc(), Zlib()])
66+
def test_roundtrip_v2(store: zarr.abc.store.Store, dataset: xr.Dataset, compressor: Codec) -> None:
67+
encoding = {
68+
"var1": {
69+
"compressor": compressor,
70+
}
71+
}
72+
dataset.to_zarr(store, encoding=encoding, zarr_format=2)
6573
other_dataset = xr.open_dataset(store, engine="zarr")
6674
assert dataset.identical(other_dataset)
75+
assert isinstance(other_dataset.var1.encoding["compressor"], compressor.__class__)
6776

6877
other_dataset = xr.open_zarr(store)
6978
assert dataset.identical(other_dataset)

0 commit comments

Comments
 (0)