File tree Expand file tree Collapse file tree 4 files changed +16
-8
lines changed
Expand file tree Collapse file tree 4 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 1+ When creating arrays without explicitly specifying a chunk size using `zarr.create ` and other
2+ array creation routines, the chunk size will now set automatically instead of defaulting to the data shape.
3+ For large arrays this will result in smaller default chunk sizes.
4+ To retain previous behaviour, explicitly set the chunk shape to the data shape.
5+
6+ This fix matches the existing chunking behaviour of
7+ `zarr.save_array ` and `zarr.api.asynchronous.AsyncArray.create `.
Original file line number Diff line number Diff line change @@ -992,19 +992,11 @@ async def create(
992992 )
993993
994994 if zarr_format == 2 :
995- if chunks is None :
996- chunks = shape
997995 dtype = parse_dtype (dtype , zarr_format )
998996 if not filters :
999997 filters = _default_filters (dtype )
1000998 if compressor == "auto" :
1001999 compressor = _default_compressor (dtype )
1002- elif zarr_format == 3 and chunk_shape is None : # type: ignore[redundant-expr]
1003- if chunks is not None :
1004- chunk_shape = chunks
1005- chunks = None
1006- else :
1007- chunk_shape = shape
10081000
10091001 if synchronizer is not None :
10101002 warnings .warn ("synchronizer is not yet implemented" , RuntimeWarning , stacklevel = 2 )
Original file line number Diff line number Diff line change @@ -64,6 +64,9 @@ def _guess_chunks(
6464 if isinstance (shape , int ):
6565 shape = (shape ,)
6666
67+ if typesize == 0 :
68+ return shape
69+
6770 ndims = len (shape )
6871 # require chunks to have non-zero length for all dimensions
6972 chunks = np .maximum (np .array (shape , dtype = "=f8" ), 1 )
Original file line number Diff line number Diff line change @@ -1301,3 +1301,9 @@ def test_no_overwrite_load(tmp_path: Path) -> None:
13011301 with contextlib .suppress (NotImplementedError ):
13021302 zarr .load (store )
13031303 assert existing_fpath .exists ()
1304+
1305+
1306+ def test_auto_chunks () -> None :
1307+ # Check chunks are automatically set to a sensible default
1308+ a = zarr .ones (shape = (1000 , 1000 ), dtype = np .uint8 )
1309+ assert a .chunks == (500 , 500 )
You can’t perform that action at this time.
0 commit comments