2626 FiltersParam ,
2727 _get_default_chunk_encoding_v2 ,
2828 _get_default_chunk_encoding_v3 ,
29+ _parse_chunk_encoding_v2 ,
2930 _parse_chunk_encoding_v3 ,
3031 chunks_initialized ,
3132 create_array ,
@@ -953,42 +954,26 @@ def test_chunks_and_shards() -> None:
953954 assert arr_v2 .shards is None
954955
955956
956- @pytest .mark .parametrize ("store" , ["memory" ], indirect = True )
957- @pytest .mark .parametrize (
958- "compressors" ,
959- [
960- "auto" ,
961- (ZstdCodec (level = 3 ),),
962- (ZstdCodec (level = 3 ), GzipCodec (level = 0 )),
963- ZstdCodec (level = 3 ),
964- {"name" : "zstd" , "configuration" : {"level" : 3 }},
965- ({"name" : "zstd" , "configuration" : {"level" : 3 }},),
966- ],
967- )
968- async def test_create_array_v3_compressors (
969- store : MemoryStore , compressors : CompressorsParam
970- ) -> None :
971- """
972- Test various possibilities for the compressors parameter to create_array
973- """
974- dtype = "uint8"
975- arr = await create_array (
976- store = store ,
977- dtype = dtype ,
978- shape = (10 ,),
979- zarr_format = 3 ,
980- compressors = compressors ,
981- )
982- _ , _ , bb_codecs_expected = _parse_chunk_encoding_v3 (
983- filters = (), compressors = compressors , array_bytes_codec = "auto" , dtype = np .dtype (dtype )
984- )
985- # TODO: find a better way to get the compressors from the array.
986- assert arr .codec_pipeline .bytes_bytes_codecs == bb_codecs_expected # type: ignore[attr-defined]
957+ def test_create_array_default_fill_values () -> None :
958+ a = zarr .create_array (MemoryStore (), shape = 5 , chunks = 5 , dtype = "<U4" )
959+ assert a .fill_value == ""
960+
961+ b = zarr .create_array (MemoryStore (), shape = 5 , chunks = 5 , dtype = "<S4" )
962+ assert b .fill_value == b""
963+
964+ c = zarr .create_array (MemoryStore (), shape = 5 , chunks = 5 , dtype = "i" )
965+ assert c .fill_value == 0
966+
967+ d = zarr .create_array (MemoryStore (), shape = 5 , chunks = 5 , dtype = "f" )
968+ assert d .fill_value == 0.0
987969
988970
989971@pytest .mark .parametrize ("store" , ["memory" ], indirect = True )
990972@pytest .mark .parametrize ("dtype" , ["uint8" , "float32" , "str" ])
991- async def test_create_array_no_filters_compressors (store : MemoryStore , dtype : str ) -> None :
973+ @pytest .mark .parametrize ("empty_value" , [None , ()])
974+ async def test_create_array_no_filters_compressors (
975+ store : MemoryStore , dtype : str , empty_value : Any
976+ ) -> None :
992977 """
993978 Test that the default ``filters`` and ``compressors`` are removed when ``create_array`` is invoked.
994979 """
@@ -999,30 +984,21 @@ async def test_create_array_no_filters_compressors(store: MemoryStore, dtype: st
999984 dtype = dtype ,
1000985 shape = (10 ,),
1001986 zarr_format = 2 ,
1002- compressors = None ,
1003- filters = None ,
987+ compressors = empty_value ,
988+ filters = empty_value ,
1004989 )
1005- assert arr .metadata .filters is None # type: ignore[union-attr]
1006- assert arr .metadata .compressor is None # type: ignore[union-attr]
1007-
1008- arr = await create_array (
1009- store = store ,
1010- dtype = dtype ,
1011- shape = (10 ,),
1012- zarr_format = 2 ,
1013- compressors = (),
1014- filters = (),
1015- )
1016- assert arr .metadata .filters == () # type: ignore[union-attr]
990+ # The v2 metadata stores None and () separately
991+ assert arr .metadata .filters == empty_value # type: ignore[union-attr]
992+ # The v2 metadata does not allow tuple for compressor, therefore it is turned into None
1017993 assert arr .metadata .compressor is None # type: ignore[union-attr]
1018994
1019995 # v3
1020996 arr = await create_array (
1021997 store = store ,
1022998 dtype = dtype ,
1023999 shape = (10 ,),
1024- compressors = () ,
1025- filters = () ,
1000+ compressors = empty_value ,
1001+ filters = empty_value ,
10261002 )
10271003 if dtype == "str" :
10281004 assert arr .metadata .codecs == [VLenUTF8Codec ()] # type: ignore[union-attr]
@@ -1031,10 +1007,26 @@ async def test_create_array_no_filters_compressors(store: MemoryStore, dtype: st
10311007
10321008
10331009@pytest .mark .parametrize ("store" , ["memory" ], indirect = True )
1010+ @pytest .mark .parametrize ("dtype" , ["uint8" , "float32" , "str" ])
1011+ @pytest .mark .parametrize (
1012+ "compressors" ,
1013+ [
1014+ "auto" ,
1015+ None ,
1016+ (),
1017+ (ZstdCodec (level = 3 ),),
1018+ (ZstdCodec (level = 3 ), GzipCodec (level = 0 )),
1019+ ZstdCodec (level = 3 ),
1020+ {"name" : "zstd" , "configuration" : {"level" : 3 }},
1021+ ({"name" : "zstd" , "configuration" : {"level" : 3 }},),
1022+ ],
1023+ )
10341024@pytest .mark .parametrize (
10351025 "filters" ,
10361026 [
10371027 "auto" ,
1028+ None ,
1029+ (),
10381030 (
10391031 TransposeCodec (
10401032 order = [
@@ -1063,23 +1055,60 @@ async def test_create_array_no_filters_compressors(store: MemoryStore, dtype: st
10631055 ({"name" : "transpose" , "configuration" : {"order" : [0 ]}},),
10641056 ],
10651057)
1066- async def test_create_array_v3_filters (store : MemoryStore , filters : FiltersParam ) -> None :
1058+ async def test_create_array_v3_chunk_encoding (
1059+ store : MemoryStore , compressors : CompressorsParam , filters : FiltersParam , dtype : str
1060+ ) -> None :
10671061 """
1068- Test various possibilities for the filters parameter to create_array
1062+ Test various possibilities for the compressors and filters parameter to create_array
10691063 """
1070- dtype = "uint8"
10711064 arr = await create_array (
10721065 store = store ,
10731066 dtype = dtype ,
10741067 shape = (10 ,),
10751068 zarr_format = 3 ,
10761069 filters = filters ,
1070+ compressors = compressors ,
10771071 )
1078- aa_codecs_expected , _ , _ = _parse_chunk_encoding_v3 (
1079- filters = filters , compressors = () , array_bytes_codec = "auto" , dtype = np .dtype (dtype )
1072+ aa_codecs_expected , _ , bb_codecs_expected = _parse_chunk_encoding_v3 (
1073+ filters = filters , compressors = compressors , array_bytes_codec = "auto" , dtype = np .dtype (dtype )
10801074 )
1081- # TODO: find a better way to get the filters from the array.
1075+ # TODO: find a better way to get the filters / compressors from the array.
10821076 assert arr .codec_pipeline .array_array_codecs == aa_codecs_expected # type: ignore[attr-defined]
1077+ assert arr .codec_pipeline .bytes_bytes_codecs == bb_codecs_expected # type: ignore[attr-defined]
1078+
1079+
1080+ @pytest .mark .parametrize ("store" , ["memory" ], indirect = True )
1081+ @pytest .mark .parametrize ("dtype" , ["uint8" , "float32" , "str" ])
1082+ @pytest .mark .parametrize (
1083+ "compressors" ,
1084+ [
1085+ "auto" ,
1086+ None ,
1087+ numcodecs .Zstd (level = 3 ),
1088+ (),
1089+ (numcodecs .Zstd (level = 3 ),),
1090+ ],
1091+ )
1092+ @pytest .mark .parametrize (
1093+ "filters" , ["auto" , None , numcodecs .GZip (level = 1 ), (numcodecs .GZip (level = 1 ),)]
1094+ )
1095+ async def test_create_array_v2_chunk_encoding (
1096+ store : MemoryStore , compressors : CompressorsParam , filters : FiltersParam , dtype : str
1097+ ) -> None :
1098+ arr = await create_array (
1099+ store = store ,
1100+ dtype = dtype ,
1101+ shape = (10 ,),
1102+ zarr_format = 2 ,
1103+ compressors = compressors ,
1104+ filters = filters ,
1105+ )
1106+ filters_expected , compressor_expected = _parse_chunk_encoding_v2 (
1107+ filters = filters , compressor = compressors , dtype = np .dtype (dtype )
1108+ )
1109+ # TODO: find a better way to get the filters/compressor from the array.
1110+ assert arr .metadata .compressor == compressor_expected # type: ignore[union-attr]
1111+ assert arr .metadata .filters == filters_expected # type: ignore[union-attr]
10831112
10841113
10851114@pytest .mark .parametrize ("store" , ["memory" ], indirect = True )
0 commit comments