Skip to content

Commit

Permalink
handle singleton compressor / filters input
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b committed Dec 22, 2024
1 parent 669ad72 commit ae1832d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/zarr/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import warnings
from asyncio import gather
from collections.abc import Iterable
from collections.abc import Iterable, Mapping
from dataclasses import dataclass, field
from itertools import starmap
from logging import getLogger
Expand Down Expand Up @@ -3594,7 +3594,10 @@ async def create_array(
config=config_parsed,
)
else:
sub_codecs = _parse_chunk_encoding_v3(compression=compression, filters=filters, dtype=dtype)
array_array, array_bytes, bytes_bytes = _parse_chunk_encoding_v3(
compression=compression, filters=filters, dtype=dtype_parsed
)
sub_codecs = (*array_array, array_bytes, *bytes_bytes)
codecs_out: tuple[Codec, ...]
if shard_shape_parsed is not None:
sharding_codec = ShardingCodec(chunk_shape=chunk_shape_parsed, codecs=sub_codecs)
Expand Down Expand Up @@ -3750,10 +3753,16 @@ def _parse_chunk_encoding_v3(
if compression == "auto":
out_bytes_bytes = default_bytes_bytes
else:
out_bytes_bytes = tuple(compression)
if isinstance(compression, Mapping | Codec):
out_bytes_bytes = (compression,)
else:
out_bytes_bytes = tuple(compression)
if filters == "auto":
out_array_array = default_array_array
else:
out_array_array = tuple(filters)
if isinstance(filters, Mapping | Codec):
out_array_array = (filters,)
else:
out_array_array = tuple(filters)

return out_array_array, default_array_bytes, out_bytes_bytes
4 changes: 2 additions & 2 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,8 @@ async def create_array(
name=name,
shape=shape,
dtype=dtype,
chunk_shape=chunk_shape,
shard_shape=shard_shape,
chunks=chunk_shape,
shards=shard_shape,
filters=filters,
compression=compression,
fill_value=fill_value,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_store/test_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_api_integration(self, store: ZipStore) -> None:

data = np.arange(10000, dtype=np.uint16).reshape(100, 100)
z = root.create_array(
shape=data.shape, chunks=(10, 10), name="foo", dtype=np.uint16, fill_value=99
shape=data.shape, chunk_shape=(10, 10), name="foo", dtype=np.uint16, fill_value=99
)
z[:] = data

Expand Down
2 changes: 1 addition & 1 deletion tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async def test_v2_encode_decode(dtype):
g.create_array(
name="foo",
shape=(3,),
chunks=(3,),
chunk_shape=(3,),
dtype=dtype,
fill_value=b"X",
)
Expand Down

0 comments on commit ae1832d

Please sign in to comment.