Skip to content

Commit 9eb2d28

Browse files
d-v-bTomAugspurger
andauthored
docstring cleanup (#3390)
* make docs more consistent, and remove outdated references to configuration values that no longer work * add tests for consistent docstrings * add flagrantly failing test for consistent parameter docstrings * add test for consistent docstring usage * add missing docstring and re-parametrize test * fix rst * update docstring for make_store_path * ArrayConfigLike contains ArrayConfig * update chunks docstrings * typo * changelog * Update src/zarr/api/asynchronous.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/core/array.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/api/asynchronous.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/api/synchronous.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/core/array.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/core/array.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/core/array.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/core/group.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/core/group.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/core/group.py Co-authored-by: Tom Augspurger <[email protected]> * Update src/zarr/core/array.py Co-authored-by: Tom Augspurger <[email protected]> * normalize more docstrings, and make docstring tests easier to interpret --------- Co-authored-by: Tom Augspurger <[email protected]>
1 parent 62d1a6a commit 9eb2d28

File tree

9 files changed

+613
-274
lines changed

9 files changed

+613
-274
lines changed

changes/3390.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve documentation consistency across API functions and remove outdated references to deprecated configuration values that no longer work.

docs/user-guide/config.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Configuration options include the following:
2828

2929
- Default Zarr format ``default_zarr_version``
3030
- Default array order in memory ``array.order``
31-
- Default filters, serializers and compressors, e.g. ``array.v3_default_filters``, ``array.v3_default_serializer``, ``array.v3_default_compressors``, ``array.v2_default_filters`` and ``array.v2_default_compressor``
3231
- Whether empty chunks are written to storage ``array.write_empty_chunks``
3332
- Async and threading options, e.g. ``async.concurrency`` and ``threading.max_workers``
3433
- Selections of implementations of codecs, codec pipelines and buffers

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ test = [
7878
"pytest-accept",
7979
"rich",
8080
"mypy",
81+
'numpydoc',
8182
"hypothesis",
8283
"pytest-xdist",
8384
"packaging",

src/zarr/api/asynchronous.py

Lines changed: 77 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ async def load(
281281
282282
Parameters
283283
----------
284-
store : Store or str
284+
store : StoreLike
285285
Store or path to directory in file system or name of zip file.
286286
path : str or None, optional
287287
The path within the store from which to load.
@@ -325,7 +325,7 @@ async def open(
325325
326326
Parameters
327327
----------
328-
store : Store or str, optional
328+
store : StoreLike or None, default=None
329329
Store or path to directory in file system or name of zip file.
330330
mode : {'r', 'r+', 'a', 'w', 'w-'}, optional
331331
Persistence mode: 'r' means read only (must exist); 'r+' means
@@ -338,8 +338,8 @@ async def open(
338338
path : str or None, optional
339339
The path within the store to open.
340340
storage_options : dict
341-
If the store is backed by an fsspec-based implementation, then this dict will be passed to
342-
the Store constructor for that implementation. Ignored otherwise.
341+
If using an fsspec URL to create the store, these will be passed to
342+
the backend implementation. Ignored otherwise.
343343
**kwargs
344344
Additional parameters are passed through to :func:`zarr.creation.open_array` or
345345
:func:`zarr.hierarchy.open_group`.
@@ -409,7 +409,7 @@ async def save(
409409
410410
Parameters
411411
----------
412-
store : Store or str
412+
store : StoreLike
413413
Store or path to directory in file system or name of zip file.
414414
*args : ndarray
415415
NumPy arrays with data to save.
@@ -445,12 +445,13 @@ async def save_array(
445445
446446
Parameters
447447
----------
448-
store : Store or str
448+
store : StoreLike
449449
Store or path to directory in file system or name of zip file.
450450
arr : ndarray
451451
NumPy array with data to save.
452452
zarr_format : {2, 3, None}, optional
453-
The zarr format to use when saving (default is 3 if not specified).
453+
The zarr format to use when saving. The default is ``None``, which will
454+
use the default Zarr format defined in the global configuration object.
454455
path : str or None, optional
455456
The path within the store where the array will be saved.
456457
storage_options : dict
@@ -500,7 +501,7 @@ async def save_group(
500501
501502
Parameters
502503
----------
503-
store : Store or str
504+
store : StoreLike
504505
Store or path to directory in file system or name of zip file.
505506
*args : ndarray
506507
NumPy arrays with data to save.
@@ -649,14 +650,13 @@ async def group(
649650
650651
Parameters
651652
----------
652-
store : Store or str, optional
653-
Store or path to directory in file system.
653+
store : StoreLike or None, default=None
654+
Store or path to directory in file system or name of zip file.
654655
overwrite : bool, optional
655656
If True, delete any pre-existing data in `store` at `path` before
656657
creating the group.
657-
chunk_store : Store, optional
658-
Separate storage for chunks. If not provided, `store` will be used
659-
for storage of both chunks and metadata.
658+
chunk_store : StoreLike or None, default=None
659+
Separate storage for chunks. Not implemented.
660660
cache_attrs : bool, optional
661661
If True (default), user attributes will be cached for attribute read
662662
operations. If False, user attributes are reloaded from the store prior
@@ -712,8 +712,8 @@ async def create_group(
712712
713713
Parameters
714714
----------
715-
store : Store or str
716-
Store or path to directory in file system.
715+
store : StoreLike
716+
Store or path to directory in file system or name of zip file.
717717
path : str, optional
718718
Group path within store.
719719
overwrite : bool, optional
@@ -768,7 +768,7 @@ async def open_group(
768768
769769
Parameters
770770
----------
771-
store : Store, str, or mapping, optional
771+
store : StoreLike or None, default=None
772772
Store or path to directory in file system or name of zip file.
773773
774774
Strings are interpreted as paths on the local file system
@@ -793,7 +793,7 @@ async def open_group(
793793
Array synchronizer.
794794
path : str, optional
795795
Group path within store.
796-
chunk_store : Store or str, optional
796+
chunk_store : StoreLike or None, default=None
797797
Store or path to directory in file system or name of zip file.
798798
storage_options : dict
799799
If using an fsspec URL to create the store, these will be passed to
@@ -869,7 +869,7 @@ async def create(
869869
compressor: CompressorLike = "auto",
870870
fill_value: Any | None = DEFAULT_FILL_VALUE,
871871
order: MemoryOrder | None = None,
872-
store: str | StoreLike | None = None,
872+
store: StoreLike | None = None,
873873
synchronizer: Any | None = None,
874874
overwrite: bool = False,
875875
path: PathLike | None = None,
@@ -906,65 +906,58 @@ async def create(
906906
shape : int or tuple of ints
907907
Array shape.
908908
chunks : int or tuple of ints, optional
909-
The shape of the array's chunks.
910-
Zarr format 2 only. Zarr format 3 arrays should use `chunk_shape` instead.
911-
If not specified, default values are guessed based on the shape and dtype.
909+
Chunk shape. If True, will be guessed from ``shape`` and ``dtype``. If
910+
False, will be set to ``shape``, i.e., single chunk for the whole array.
911+
If an int, the chunk size in each dimension will be given by the value
912+
of ``chunks``. Default is True.
912913
dtype : str or dtype, optional
913914
NumPy dtype.
914-
chunk_shape : int or tuple of ints, optional
915-
The shape of the Array's chunks (default is None).
916-
Zarr format 3 only. Zarr format 2 arrays should use `chunks` instead.
917-
chunk_key_encoding : ChunkKeyEncoding, optional
918-
A specification of how the chunk keys are represented in storage.
919-
Zarr format 3 only. Zarr format 2 arrays should use `dimension_separator` instead.
920-
Default is ``("default", "/")``.
921-
codecs : Sequence of Codecs or dicts, optional
922-
An iterable of Codec or dict serializations of Codecs. The elements of
923-
this collection specify the transformation from array values to stored bytes.
924-
Zarr format 3 only. Zarr format 2 arrays should use ``filters`` and ``compressor`` instead.
925-
926-
If no codecs are provided, default codecs will be used:
927-
928-
- For numeric arrays, the default is ``BytesCodec`` and ``ZstdCodec``.
929-
- For Unicode strings, the default is ``VLenUTF8Codec`` and ``ZstdCodec``.
930-
- For bytes or objects, the default is ``VLenBytesCodec`` and ``ZstdCodec``.
931-
932-
These defaults can be changed by modifying the value of ``array.v3_default_filters``,
933-
``array.v3_default_serializer`` and ``array.v3_default_compressors`` in :mod:`zarr.core.config`.
934915
compressor : Codec, optional
935916
Primary compressor to compress chunk data.
936917
Zarr format 2 only. Zarr format 3 arrays should use ``codecs`` instead.
937918
938-
If neither ``compressor`` nor ``filters`` are provided, a default compressor will be used:
939-
940-
- For numeric arrays, the default is ``ZstdCodec``.
941-
- For Unicode strings, the default is ``VLenUTF8Codec``.
942-
- For bytes or objects, the default is ``VLenBytesCodec``.
919+
If neither ``compressor`` nor ``filters`` are provided, the default compressor
920+
:class:`zarr.codecs.ZstdCodec` is used.
943921
944-
These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`.
945-
fill_value : object
946-
Default value to use for uninitialized portions of the array.
922+
If ``compressor`` is set to ``None``, no compression is used.
923+
fill_value : Any, optional
924+
Fill value for the array.
947925
order : {'C', 'F'}, optional
948926
Deprecated in favor of the ``config`` keyword argument.
949927
Pass ``{'order': <value>}`` to ``create`` instead of using this parameter.
950928
Memory layout to be used within each chunk.
951929
If not specified, the ``array.order`` parameter in the global config will be used.
952-
store : Store or str
930+
store : StoreLike or None, default=None
953931
Store or path to directory in file system or name of zip file.
954932
synchronizer : object, optional
955933
Array synchronizer.
956934
overwrite : bool, optional
957-
If True, delete all pre-existing data in `store` at `path` before
935+
If True, delete all pre-existing data in ``store`` at ``path`` before
958936
creating the array.
959937
path : str, optional
960938
Path under which array is stored.
961-
chunk_store : MutableMapping, optional
962-
Separate storage for chunks. If not provided, `store` will be used
939+
chunk_store : StoreLike or None, default=None
940+
Separate storage for chunks. If not provided, ``store`` will be used
963941
for storage of both chunks and metadata.
964-
filters : sequence of Codecs, optional
965-
Sequence of filters to use to encode chunk data prior to compression.
966-
Zarr format 2 only. If no ``filters`` are provided, a default set of filters will be used.
967-
These defaults can be changed by modifying the value of ``array.v2_default_filters`` in :mod:`zarr.core.config`.
942+
filters : Iterable[Codec] | Literal["auto"], optional
943+
Iterable of filters to apply to each chunk of the array, in order, before serializing that
944+
chunk to bytes.
945+
946+
For Zarr format 3, a "filter" is a codec that takes an array and returns an array,
947+
and these values must be instances of :class:`zarr.abc.codec.ArrayArrayCodec`, or a
948+
dict representations of :class:`zarr.abc.codec.ArrayArrayCodec`.
949+
950+
For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the
951+
the order if your filters is consistent with the behavior of each filter.
952+
953+
The default value of ``"auto"`` instructs Zarr to use a default used based on the data
954+
type of the array and the Zarr format specified. For all data types in Zarr V3, and most
955+
data types in Zarr V2, the default filters are empty. The only cases where default filters
956+
are not empty is when the Zarr format is 2, and the data type is a variable-length data type like
957+
:class:`zarr.dtype.VariableLengthUTF8` or :class:`zarr.dtype.VariableLengthUTF8`. In these cases,
958+
the default filters contains a single element which is a codec specific to that particular data type.
959+
960+
To create an array with no filters, provide an empty iterable or the value ``None``.
968961
cache_metadata : bool, optional
969962
If True, array configuration metadata will be cached for the
970963
lifetime of the object. If False, array metadata will be reloaded
@@ -981,7 +974,6 @@ async def create(
981974
dimension_separator : {'.', '/'}, optional
982975
Separator placed between the dimensions of a chunk.
983976
Zarr format 2 only. Zarr format 3 arrays should use ``chunk_key_encoding`` instead.
984-
Default is ".".
985977
write_empty_chunks : bool, optional
986978
Deprecated in favor of the ``config`` keyword argument.
987979
Pass ``{'write_empty_chunks': <value>}`` to ``create`` instead of using this parameter.
@@ -991,15 +983,36 @@ async def create(
991983
that chunk is not be stored, and the store entry for that chunk's key
992984
is deleted.
993985
zarr_format : {2, 3, None}, optional
994-
The zarr format to use when saving.
995-
Default is 3.
986+
The Zarr format to use when creating an array. The default is ``None``,
987+
which instructs Zarr to choose the default Zarr format value defined in the
988+
runtime configuration.
996989
meta_array : array-like, optional
997-
An array instance to use for determining arrays to create and return
998-
to users. Use `numpy.empty(())` by default.
990+
Not implemented.
991+
attributes : dict[str, JSON], optional
992+
A dictionary of user attributes to store with the array.
993+
chunk_shape : int or tuple of ints, optional
994+
The shape of the Array's chunks (default is None).
995+
Zarr format 3 only. Zarr format 2 arrays should use `chunks` instead.
996+
chunk_key_encoding : ChunkKeyEncoding, optional
997+
A specification of how the chunk keys are represented in storage.
998+
Zarr format 3 only. Zarr format 2 arrays should use `dimension_separator` instead.
999+
Default is ``("default", "/")``.
1000+
codecs : Sequence of Codecs or dicts, optional
1001+
An iterable of Codec or dict serializations of Codecs. Zarr V3 only.
1002+
1003+
The elements of ``codecs`` specify the transformation from array values to stored bytes.
1004+
Zarr format 3 only. Zarr format 2 arrays should use ``filters`` and ``compressor`` instead.
1005+
1006+
If no codecs are provided, default codecs will be used based on the data type of the array.
1007+
For most data types, the default codecs are the tuple ``(BytesCodec(), ZstdCodec())``;
1008+
data types that require a special :class:`zarr.abc.codec.ArrayBytesCodec`, like variable-length strings or bytes,
1009+
will use the :class:`zarr.abc.codec.ArrayBytesCodec` required for the data type instead of :class:`zarr.codecs.BytesCodec`.
1010+
dimension_names : Iterable[str | None] | None = None
1011+
An iterable of dimension names. Zarr format 3 only.
9991012
storage_options : dict
10001013
If using an fsspec URL to create the store, these will be passed to
10011014
the backend implementation. Ignored otherwise.
1002-
config : ArrayConfig or ArrayConfigLike, optional
1015+
config : ArrayConfigLike, optional
10031016
Runtime configuration of the array. If provided, will override the
10041017
default values from `zarr.config.array`.
10051018
@@ -1224,7 +1237,7 @@ async def open_array(
12241237
12251238
Parameters
12261239
----------
1227-
store : Store or str
1240+
store : StoreLike
12281241
Store or path to directory in file system or name of zip file.
12291242
zarr_version : {2, 3, None}, optional
12301243
The zarr format to use when saving. Deprecated in favor of zarr_format.

0 commit comments

Comments
 (0)