| 
12 | 12 | 
 
  | 
13 | 13 | import zarr.api.asynchronous  | 
14 | 14 | from zarr import Array, AsyncArray, Group  | 
15 |  | -from zarr.codecs import BytesCodec, VLenBytesCodec, ZstdCodec  | 
16 |  | -from zarr.codecs.gzip import GzipCodec  | 
17 |  | -from zarr.codecs.transpose import TransposeCodec  | 
 | 15 | +from zarr.codecs import (  | 
 | 16 | +    BytesCodec,  | 
 | 17 | +    GzipCodec,  | 
 | 18 | +    TransposeCodec,  | 
 | 19 | +    VLenBytesCodec,  | 
 | 20 | +    VLenUTF8Codec,  | 
 | 21 | +    ZstdCodec,  | 
 | 22 | +)  | 
18 | 23 | from zarr.core._info import ArrayInfo  | 
19 | 24 | from zarr.core.array import (  | 
20 | 25 |     CompressorsParam,  | 
@@ -946,6 +951,56 @@ def test_chunks_and_shards() -> None:  | 
946 | 951 |     assert arr_v2.shards is None  | 
947 | 952 | 
 
  | 
948 | 953 | 
 
  | 
 | 954 | +def test_create_array_default_fill_values() -> None:  | 
 | 955 | +    a = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<U4")  | 
 | 956 | +    assert a.fill_value == ""  | 
 | 957 | + | 
 | 958 | +    b = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="<S4")  | 
 | 959 | +    assert b.fill_value == b""  | 
 | 960 | + | 
 | 961 | +    c = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="i")  | 
 | 962 | +    assert c.fill_value == 0  | 
 | 963 | + | 
 | 964 | +    d = zarr.create_array(MemoryStore(), shape=5, chunks=5, dtype="f")  | 
 | 965 | +    assert d.fill_value == 0.0  | 
 | 966 | + | 
 | 967 | + | 
 | 968 | +@pytest.mark.parametrize("store", ["memory"], indirect=True)  | 
 | 969 | +@pytest.mark.parametrize("dtype", ["uint8", "float32", "str"])  | 
 | 970 | +@pytest.mark.parametrize("empty_value", [None, ()])  | 
 | 971 | +async def test_create_array_no_filters_compressors(  | 
 | 972 | +    store: MemoryStore, dtype: str, empty_value: Any  | 
 | 973 | +) -> None:  | 
 | 974 | +    """  | 
 | 975 | +    Test that the default ``filters`` and ``compressors`` are removed when ``create_array`` is invoked.  | 
 | 976 | +    """  | 
 | 977 | + | 
 | 978 | +    # v2  | 
 | 979 | +    arr = await create_array(  | 
 | 980 | +        store=store,  | 
 | 981 | +        dtype=dtype,  | 
 | 982 | +        shape=(10,),  | 
 | 983 | +        zarr_format=2,  | 
 | 984 | +        compressors=empty_value,  | 
 | 985 | +        filters=empty_value,  | 
 | 986 | +    )  | 
 | 987 | +    assert arr.metadata.filters == empty_value  # type: ignore[union-attr]  | 
 | 988 | +    assert arr.metadata.compressor is None  # type: ignore[union-attr]  | 
 | 989 | + | 
 | 990 | +    # v3  | 
 | 991 | +    arr = await create_array(  | 
 | 992 | +        store=store,  | 
 | 993 | +        dtype=dtype,  | 
 | 994 | +        shape=(10,),  | 
 | 995 | +        compressors=empty_value,  | 
 | 996 | +        filters=empty_value,  | 
 | 997 | +    )  | 
 | 998 | +    if dtype == "str":  | 
 | 999 | +        assert arr.metadata.codecs == [VLenUTF8Codec()]  # type: ignore[union-attr]  | 
 | 1000 | +    else:  | 
 | 1001 | +        assert arr.metadata.codecs == [BytesCodec()]  # type: ignore[union-attr]  | 
 | 1002 | + | 
 | 1003 | + | 
949 | 1004 | @pytest.mark.parametrize("store", ["memory"], indirect=True)  | 
950 | 1005 | @pytest.mark.parametrize(  | 
951 | 1006 |     "compressors",  | 
 | 
0 commit comments