|
7 | 7 | import pytest |
8 | 8 | from numcodecs import Delta |
9 | 9 | from numcodecs.blosc import Blosc |
| 10 | +from numcodecs.zstd import Zstd |
10 | 11 |
|
11 | 12 | import zarr |
12 | 13 | import zarr.core.buffer |
13 | 14 | import zarr.storage |
14 | 15 | from zarr import config |
| 16 | +from zarr.abc.store import Store |
15 | 17 | from zarr.core.buffer.core import default_buffer_prototype |
16 | 18 | from zarr.core.sync import sync |
17 | 19 | from zarr.storage import MemoryStore, StorePath |
@@ -100,11 +102,7 @@ async def test_v2_encode_decode(dtype, expected_dtype, fill_value, fill_value_en |
100 | 102 | store = zarr.storage.MemoryStore() |
101 | 103 | g = zarr.group(store=store, zarr_format=2) |
102 | 104 | g.create_array( |
103 | | - name="foo", |
104 | | - shape=(3,), |
105 | | - chunks=(3,), |
106 | | - dtype=dtype, |
107 | | - fill_value=fill_value, |
| 105 | + name="foo", shape=(3,), chunks=(3,), dtype=dtype, fill_value=fill_value, compressor=None |
108 | 106 | ) |
109 | 107 |
|
110 | 108 | result = await store.get("foo/.zarray", zarr.core.buffer.default_buffer_prototype()) |
@@ -173,6 +171,29 @@ def test_v2_filters_codecs(filters: Any, order: Literal["C", "F"]) -> None: |
173 | 171 | np.testing.assert_array_equal(result, array_fixture) |
174 | 172 |
|
175 | 173 |
|
| 174 | +@pytest.mark.filterwarnings("ignore") |
| 175 | +@pytest.mark.parametrize("store", ["memory"], indirect=True) |
| 176 | +def test_create_array_defaults(store: Store): |
| 177 | + """ |
| 178 | + Test that passing compressor=None results in no compressor. Also test that the default value of the compressor |
| 179 | + parameter does produce a compressor. |
| 180 | + """ |
| 181 | + g = zarr.open(store, mode="w", zarr_format=2) |
| 182 | + arr = g.create_array("one", dtype="i8", shape=(1,), chunks=(1,), compressor=None) |
| 183 | + assert arr._async_array.compressor is None |
| 184 | + assert not (arr.filters) |
| 185 | + arr = g.create_array("two", dtype="i8", shape=(1,), chunks=(1,)) |
| 186 | + assert arr._async_array.compressor is not None |
| 187 | + assert not (arr.filters) |
| 188 | + arr = g.create_array("three", dtype="i8", shape=(1,), chunks=(1,), compressor=Zstd()) |
| 189 | + assert arr._async_array.compressor is not None |
| 190 | + assert not (arr.filters) |
| 191 | + with pytest.raises(ValueError): |
| 192 | + g.create_array( |
| 193 | + "four", dtype="i8", shape=(1,), chunks=(1,), compressor=None, compressors=None |
| 194 | + ) |
| 195 | + |
| 196 | + |
176 | 197 | @pytest.mark.parametrize("array_order", ["C", "F"]) |
177 | 198 | @pytest.mark.parametrize("data_order", ["C", "F"]) |
178 | 199 | @pytest.mark.parametrize("memory_order", ["C", "F"]) |
|
0 commit comments