Skip to content

Commit c4330ef

Browse files
committed
tests for no filters+compressors
1 parent e24bdeb commit c4330ef

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/zarr/core/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3527,7 +3527,7 @@ async def create_array(
35273527
shards: ChunkCoords | Literal["auto"] | None = None,
35283528
filters: FiltersParam = "auto",
35293529
compressors: CompressorsParam = "auto",
3530-
fill_value: Any | None = 0,
3530+
fill_value: Any | None = None,
35313531
order: MemoryOrder | None = None,
35323532
zarr_format: ZarrFormat | None = 3,
35333533
attributes: dict[str, JSON] | None = None,

tests/test_array.py

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212

1313
import zarr.api.asynchronous
1414
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+
)
1823
from zarr.core._info import ArrayInfo
1924
from zarr.core.array import (
2025
CompressorsParam,
@@ -946,6 +951,56 @@ def test_chunks_and_shards() -> None:
946951
assert arr_v2.shards is None
947952

948953

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+
9491004
@pytest.mark.parametrize("store", ["memory"], indirect=True)
9501005
@pytest.mark.parametrize(
9511006
"compressors",

0 commit comments

Comments
 (0)