|
12 | 12 | import zarr.api.asynchronous |
13 | 13 | from zarr import Array, AsyncArray, Group |
14 | 14 | from zarr.codecs import BytesCodec, VLenBytesCodec, ZstdCodec |
| 15 | +from zarr.codecs.gzip import GzipCodec |
15 | 16 | from zarr.codecs.sharding import ShardingCodec |
| 17 | +from zarr.codecs.transpose import TransposeCodec |
16 | 18 | from zarr.core._info import ArrayInfo |
17 | | -from zarr.core.array import chunks_initialized |
| 19 | +from zarr.core.array import ( |
| 20 | + CompressorsParam, |
| 21 | + FiltersParam, |
| 22 | + _parse_chunk_encoding_v3, |
| 23 | + chunks_initialized, |
| 24 | +) |
18 | 25 | from zarr.core.buffer import default_buffer_prototype |
19 | 26 | from zarr.core.buffer.cpu import NDBuffer |
20 | 27 | from zarr.core.chunk_grids import _auto_partition |
@@ -957,3 +964,106 @@ def test_chunks_and_shards() -> None: |
957 | 964 | ) |
958 | 965 | assert arr_v2.chunks == chunks |
959 | 966 | assert arr_v2.shards is None |
| 967 | + |
| 968 | + |
| 969 | +@pytest.mark.parametrize("store", ["memory"], indirect=True) |
| 970 | +@pytest.mark.parametrize( |
| 971 | + "compressors", |
| 972 | + [ |
| 973 | + "auto", |
| 974 | + (ZstdCodec(level=3),), |
| 975 | + (ZstdCodec(level=3), GzipCodec(level=0)), |
| 976 | + ZstdCodec(level=3), |
| 977 | + {"name": "zstd", "configuration": {"level": 3}}, |
| 978 | + ({"name": "zstd", "configuration": {"level": 3}},), |
| 979 | + ], |
| 980 | +) |
| 981 | +async def test_create_array_v3_compressors( |
| 982 | + store: MemoryStore, compressors: CompressorsParam |
| 983 | +) -> None: |
| 984 | + """ |
| 985 | + Test various possibilities for the compressors parameter to create_array |
| 986 | + """ |
| 987 | + dtype = "uint8" |
| 988 | + arr = zarr.create_array( |
| 989 | + store=store, |
| 990 | + dtype=dtype, |
| 991 | + shape=(10,), |
| 992 | + zarr_format=3, |
| 993 | + compressors=compressors, |
| 994 | + ) |
| 995 | + _, _, bb_codecs_expected = _parse_chunk_encoding_v3( |
| 996 | + filters=(), compressors=compressors, dtype=np.dtype(dtype) |
| 997 | + ) |
| 998 | + # TODO: find a better way to get the compressors from the array. |
| 999 | + assert tuple(arr._async_array.metadata.codecs[-len(bb_codecs_expected) :]) == bb_codecs_expected # type: ignore[union-attr] |
| 1000 | + |
| 1001 | + |
| 1002 | +@pytest.mark.parametrize("store", ["memory"], indirect=True) |
| 1003 | +@pytest.mark.parametrize( |
| 1004 | + "filters", |
| 1005 | + [ |
| 1006 | + "auto", |
| 1007 | + ( |
| 1008 | + TransposeCodec( |
| 1009 | + order=[ |
| 1010 | + 0, |
| 1011 | + ] |
| 1012 | + ), |
| 1013 | + ), |
| 1014 | + ( |
| 1015 | + TransposeCodec( |
| 1016 | + order=[ |
| 1017 | + 0, |
| 1018 | + ] |
| 1019 | + ), |
| 1020 | + TransposeCodec( |
| 1021 | + order=[ |
| 1022 | + 0, |
| 1023 | + ] |
| 1024 | + ), |
| 1025 | + ), |
| 1026 | + TransposeCodec( |
| 1027 | + order=[ |
| 1028 | + 0, |
| 1029 | + ] |
| 1030 | + ), |
| 1031 | + {"name": "transpose", "configuration": {"order": [0]}}, |
| 1032 | + ({"name": "transpose", "configuration": {"order": [0]}},), |
| 1033 | + ], |
| 1034 | +) |
| 1035 | +async def test_create_array_v3_filters(store: MemoryStore, filters: FiltersParam) -> None: |
| 1036 | + """ |
| 1037 | + Test various possibilities for the filters parameter to create_array |
| 1038 | + """ |
| 1039 | + dtype = "uint8" |
| 1040 | + arr = zarr.create_array( |
| 1041 | + store=store, |
| 1042 | + dtype=dtype, |
| 1043 | + shape=(10,), |
| 1044 | + zarr_format=3, |
| 1045 | + filters=filters, |
| 1046 | + ) |
| 1047 | + aa_codecs_expected, _, _ = _parse_chunk_encoding_v3( |
| 1048 | + filters=filters, compressors=(), dtype=np.dtype(dtype) |
| 1049 | + ) |
| 1050 | + # TODO: find a better way to get the filters from the array. |
| 1051 | + assert tuple(arr._async_array.metadata.codecs[: len(aa_codecs_expected)]) == aa_codecs_expected # type: ignore[union-attr] |
| 1052 | + |
| 1053 | + |
| 1054 | +@pytest.mark.parametrize("store", ["memory"], indirect=True) |
| 1055 | +async def test_create_array_v2(store: MemoryStore) -> None: |
| 1056 | + from numcodecs import Delta, Zstd |
| 1057 | + |
| 1058 | + # TODO: fill in |
| 1059 | + dtype = "uint8" |
| 1060 | + _ = zarr.create_array( |
| 1061 | + store=store, |
| 1062 | + dtype=dtype, |
| 1063 | + shape=(10,), |
| 1064 | + shards=None, |
| 1065 | + chunks=(4,), |
| 1066 | + zarr_format=2, |
| 1067 | + filters=(Delta(dtype=dtype),), |
| 1068 | + compressors=Zstd(level=3), |
| 1069 | + ) |
0 commit comments