Skip to content

Commit 826d6bd

Browse files
committed
in from_array default shards="keep"
1 parent f17df89 commit 826d6bd

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/zarr/api/synchronous.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ def from_array(
915915
write_data: bool = True,
916916
name: str | None = None,
917917
chunks: Literal["auto", "keep"] | ChunkCoords = "keep",
918-
shards: ShardsLike | None = None,
918+
shards: ShardsLike | None | Literal["keep"] = "keep",
919919
filters: FiltersLike | Literal["keep"] = "keep",
920920
compressors: CompressorsLike | Literal["keep"] = "keep",
921921
serializer: SerializerLike | Literal["keep"] = "keep",
@@ -954,7 +954,15 @@ def from_array(
954954
955955
If not specified, defaults to "keep" if data is a zarr Array, otherwise "auto".
956956
shards : ChunkCoords, optional
957-
Shard shape of the array. The default value of ``None`` results in no sharding at all.
957+
Shard shape of the array.
958+
Following values are supported:
959+
960+
- "auto": Automatically determine the shard shape based on the array's shape and chunk shape.
961+
- "keep": Retain the shard shape of the data array if it is a zarr Array.
962+
- ChunkCoords: A tuple of integers representing the shard shape.
963+
- None: No sharding.
964+
965+
If not specified, defaults to "keep" if data is a zarr Array, otherwise None.
958966
filters : Iterable[Codec] or "auto" or "keep", optional
959967
Iterable of filters to apply to each chunk of the array, in order, before serializing that
960968
chunk to bytes.

src/zarr/core/array.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,7 +3801,7 @@ async def from_array(
38013801
write_data: bool = True,
38023802
name: str | None = None,
38033803
chunks: Literal["auto", "keep"] | ChunkCoords = "keep",
3804-
shards: ShardsLike | None = None,
3804+
shards: ShardsLike | None | Literal["keep"] = "keep",
38053805
filters: FiltersLike | Literal["keep"] = "keep",
38063806
compressors: CompressorsLike | Literal["keep"] = "keep",
38073807
serializer: SerializerLike | Literal["keep"] = "keep",
@@ -3840,7 +3840,15 @@ async def from_array(
38403840
38413841
If not specified, defaults to "keep" if data is a zarr Array, otherwise "auto".
38423842
shards : ChunkCoords, optional
3843-
Shard shape of the array. The default value of ``None`` results in no sharding at all.
3843+
Shard shape of the array.
3844+
Following values are supported:
3845+
3846+
- "auto": Automatically determine the shard shape based on the array's shape and chunk shape.
3847+
- "keep": Retain the shard shape of the data array if it is a zarr Array.
3848+
- ChunkCoords: A tuple of integers representing the shard shape.
3849+
- None: No sharding.
3850+
3851+
If not specified, defaults to "keep" if data is a zarr Array, otherwise None.
38443852
filters : Iterable[Codec] or "auto" or "keep", optional
38453853
Iterable of filters to apply to each chunk of the array, in order, before serializing that
38463854
chunk to bytes.
@@ -3979,6 +3987,8 @@ async def from_array(
39793987
if isinstance(data, Array):
39803988
if chunks == "keep":
39813989
chunks = data.chunks
3990+
if shards == "keep":
3991+
shards = data.shards
39823992
if zarr_format is None:
39833993
zarr_format = data.metadata.zarr_format
39843994
if filters == "keep":
@@ -4010,6 +4020,8 @@ async def from_array(
40104020
else:
40114021
if chunks == "keep":
40124022
chunks = "auto"
4023+
if shards == "keep":
4024+
shards = None
40134025
if zarr_format is None:
40144026
zarr_format = 3
40154027
if filters == "keep":

0 commit comments

Comments
 (0)