Skip to content

Commit 3f8de76

Browse files
authored
Merge branch 'main' into feat/concurrent-members
2 parents f25bda3 + 4cb8ddd commit 3f8de76

File tree

22 files changed

+1309
-282
lines changed

22 files changed

+1309
-282
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ repos:
2828
files: src|tests
2929
additional_dependencies:
3030
# Package dependencies
31+
- packaging
3132
- donfig
3233
- numcodecs[crc32c]
33-
- numpy
34+
- numpy==2.1 # until https://github.com/numpy/numpy/issues/28034 is resolved
3435
- typing_extensions
3536
- universal-pathlib
3637
# Tests

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"spec/v1": 'https://zarr-specs.readthedocs.io/en/latest/v1/v1.0.html',
8888
"spec/v2": "https://zarr-specs.readthedocs.io/en/latest/v2/v2.0.html",
8989
"spec/v3": "https://zarr-specs.readthedocs.io/en/latest/v3/core/v3.0.html",
90+
"license": "https://github.com/zarr-developers/zarr-python/blob/main/LICENSE.txt"
9091
}
9192

9293
# The language for content autogenerated by Sphinx. Refer to documentation

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Zarr-Python
1313
guide/index
1414
api/index
1515
release
16-
license
1716
contributing
1817
roadmap
1918

docs/license.rst

Lines changed: 0 additions & 4 deletions
This file was deleted.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ maintainers = [
2626
requires-python = ">=3.11"
2727
# If you add a new dependency here, please also add it to .pre-commit-config.yml
2828
dependencies = [
29+
'packaging>=22.0',
2930
'numpy>=1.25',
3031
'numcodecs[crc32c]>=0.14',
3132
'typing_extensions>=4.9',
@@ -173,6 +174,7 @@ serve = "sphinx-autobuild docs docs/_build --host 0.0.0.0"
173174
[tool.hatch.envs.upstream]
174175
python = "3.13"
175176
dependencies = [
177+
'packaging @ git+https://github.com/pypa/packaging',
176178
'numpy', # from scientific-python-nightly-wheels
177179
'numcodecs @ git+https://github.com/zarr-developers/numcodecs',
178180
'fsspec @ git+https://github.com/fsspec/filesystem_spec',
@@ -206,6 +208,7 @@ See Spec 0000 for details and drop schedule: https://scientific-python.org/specs
206208
"""
207209
python = "3.11"
208210
dependencies = [
211+
'packaging==22.*',
209212
'numpy==1.25.*',
210213
'numcodecs==0.14.*', # 0.14 needed for zarr3 codecs
211214
'fsspec==2022.10.0',

src/zarr/api/asynchronous.py

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
ChunkCoords,
1818
MemoryOrder,
1919
ZarrFormat,
20+
parse_dtype,
2021
)
2122
from zarr.core.config import config
2223
from zarr.core.group import AsyncGroup, ConsolidatedMetadata, GroupMetadata
2324
from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata
25+
from zarr.core.metadata.v2 import _default_filters_and_compressor
2426
from zarr.errors import NodeTypeValidationError
2527
from zarr.storage import (
2628
StoreLike,
@@ -400,7 +402,7 @@ async def save_array(
400402
arr : ndarray
401403
NumPy array with data to save.
402404
zarr_format : {2, 3, None}, optional
403-
The zarr format to use when saving.
405+
The zarr format to use when saving (default is 3 if not specified).
404406
path : str or None, optional
405407
The path within the store where the array will be saved.
406408
storage_options : dict
@@ -773,9 +775,9 @@ async def open_group(
773775

774776

775777
async def create(
776-
shape: ChunkCoords,
778+
shape: ChunkCoords | int,
777779
*, # Note: this is a change from v2
778-
chunks: ChunkCoords | None = None, # TODO: v2 allowed chunks=True
780+
chunks: ChunkCoords | int | None = None, # TODO: v2 allowed chunks=True
779781
dtype: npt.DTypeLike | None = None,
780782
compressor: dict[str, JSON] | None = None, # TODO: default and type change
781783
fill_value: Any | None = 0, # TODO: need type
@@ -797,7 +799,7 @@ async def create(
797799
meta_array: Any | None = None, # TODO: need type
798800
attributes: dict[str, JSON] | None = None,
799801
# v3 only
800-
chunk_shape: ChunkCoords | None = None,
802+
chunk_shape: ChunkCoords | int | None = None,
801803
chunk_key_encoding: (
802804
ChunkKeyEncoding
803805
| tuple[Literal["default"], Literal[".", "/"]]
@@ -816,19 +818,45 @@ async def create(
816818
shape : int or tuple of ints
817819
Array shape.
818820
chunks : int or tuple of ints, optional
819-
Chunk shape. If True, will be guessed from `shape` and `dtype`. If
820-
False, will be set to `shape`, i.e., single chunk for the whole array.
821-
If an int, the chunk size in each dimension will be given by the value
822-
of `chunks`. Default is True.
821+
The shape of the array's chunks.
822+
V2 only. V3 arrays should use `chunk_shape` instead.
823+
If not specified, default values are guessed based on the shape and dtype.
823824
dtype : str or dtype, optional
824825
NumPy dtype.
826+
chunk_shape : int or tuple of ints, optional
827+
The shape of the Array's chunks (default is None).
828+
V3 only. V2 arrays should use `chunks` instead.
829+
chunk_key_encoding : ChunkKeyEncoding, optional
830+
A specification of how the chunk keys are represented in storage.
831+
V3 only. V2 arrays should use `dimension_separator` instead.
832+
Default is ``("default", "/")``.
833+
codecs : Sequence of Codecs or dicts, optional
834+
An iterable of Codec or dict serializations of Codecs. The elements of
835+
this collection specify the transformation from array values to stored bytes.
836+
V3 only. V2 arrays should use ``filters`` and ``compressor`` instead.
837+
838+
If no codecs are provided, default codecs will be used:
839+
840+
- For numeric arrays, the default is ``BytesCodec`` and ``ZstdCodec``.
841+
- For Unicode strings, the default is ``VLenUTF8Codec``.
842+
- For bytes or objects, the default is ``VLenBytesCodec``.
843+
844+
These defaults can be changed by modifying the value of ``array.v3_default_codecs`` in :mod:`zarr.core.config`.
825845
compressor : Codec, optional
826-
Primary compressor.
827-
fill_value : object
846+
Primary compressor to compress chunk data.
847+
V2 only. V3 arrays should use ``codecs`` instead.
848+
849+
If neither ``compressor`` nor ``filters`` are provided, a default compressor will be used:
850+
851+
- For numeric arrays, the default is ``ZstdCodec``.
852+
- For Unicode strings, the default is ``VLenUTF8Codec``.
853+
- For bytes or objects, the default is ``VLenBytesCodec``.
854+
855+
These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. fill_value : object
828856
Default value to use for uninitialized portions of the array.
829857
order : {'C', 'F'}, optional
830858
Memory layout to be used within each chunk.
831-
Default is set in Zarr's config (`array.order`).
859+
If not specified, default is taken from the Zarr config ```array.order```.
832860
store : Store or str
833861
Store or path to directory in file system or name of zip file.
834862
synchronizer : object, optional
@@ -843,6 +871,8 @@ async def create(
843871
for storage of both chunks and metadata.
844872
filters : sequence of Codecs, optional
845873
Sequence of filters to use to encode chunk data prior to compression.
874+
V2 only. If neither ``compressor`` nor ``filters`` are provided, a default
875+
compressor will be used. (see ``compressor`` for details).
846876
cache_metadata : bool, optional
847877
If True, array configuration metadata will be cached for the
848878
lifetime of the object. If False, array metadata will be reloaded
@@ -858,7 +888,8 @@ async def create(
858888
A codec to encode object arrays, only needed if dtype=object.
859889
dimension_separator : {'.', '/'}, optional
860890
Separator placed between the dimensions of a chunk.
861-
891+
V2 only. V3 arrays should use ``chunk_key_encoding`` instead.
892+
Default is ".".
862893
.. versionadded:: 2.8
863894
864895
write_empty_chunks : bool, optional
@@ -874,6 +905,7 @@ async def create(
874905
875906
zarr_format : {2, 3, None}, optional
876907
The zarr format to use when saving.
908+
Default is 3.
877909
meta_array : array-like, optional
878910
An array instance to use for determining arrays to create and return
879911
to users. Use `numpy.empty(())` by default.
@@ -893,9 +925,13 @@ async def create(
893925
or _default_zarr_version()
894926
)
895927

896-
if zarr_format == 2 and chunks is None:
897-
chunks = shape
898-
elif zarr_format == 3 and chunk_shape is None:
928+
if zarr_format == 2:
929+
if chunks is None:
930+
chunks = shape
931+
dtype = parse_dtype(dtype, zarr_format)
932+
if not filters and not compressor:
933+
filters, compressor = _default_filters_and_compressor(dtype)
934+
elif zarr_format == 3 and chunk_shape is None: # type: ignore[redundant-expr]
899935
if chunks is not None:
900936
chunk_shape = chunks
901937
chunks = None
@@ -1103,6 +1139,8 @@ async def open_array(
11031139
----------
11041140
store : Store or str
11051141
Store or path to directory in file system or name of zip file.
1142+
zarr_version : {2, 3, None}, optional
1143+
The zarr format to use when saving. Deprecated in favor of zarr_format.
11061144
zarr_format : {2, 3, None}, optional
11071145
The zarr format to use when saving.
11081146
path : str, optional

0 commit comments

Comments
 (0)