-
-
Notifications
You must be signed in to change notification settings - Fork 366
top-level functions for reading, creating data #2463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 90 commits
fd6ecd1
fa343f5
d95eba8
f6765bc
5d8445b
9526571
90bf421
de280a7
d9878cf
e5217ce
40cc7af
d7ce58b
a0dfe18
98bc328
16f5cc2
4b45ebf
750a439
7a5cbe7
215ff96
489e2a2
05dd0d8
3fbfc21
b348737
5025ad6
e204a32
68465db
d7bb121
99cc8f5
a39457f
3f0a3e0
26ced00
af55ac4
07f07ea
bc552ce
74f731a
43877c0
c693fb4
4c18aaa
dba2594
669ad72
ae1832d
5cb6dd8
5dcd80b
810ff9b
eab46a2
bcdc4cc
4e978f9
a9850bf
2747d69
023c16b
de2c36e
74d31ef
470b60f
e8b1ad1
b919483
6fcd976
d9c30a3
0bf4dd0
ea3ed0e
54fd920
a4ba7db
fb286a7
df35d13
80b5a10
77f40a5
235e246
95348d6
91a7916
665037e
ae76bb3
0a983e6
2182793
c04d7cf
144b2b7
d407e5d
1301c5f
31b3ad4
a0c1c95
43b6774
e55023a
e24bdeb
b564ae6
75b2197
2f6f8a0
c4330ef
f926a5a
95ffadd
bbe3a94
856b40f
2aa3acc
9fb8a33
99faa8e
108daa0
305fdb7
947f20e
2d2af8f
14c45cd
ff5e5cb
2afe940
e3f1f33
1643983
aad8e9d
f29b2d9
4654cbd
5cdb515
0dc7dc6
c5c761e
be60d73
ae1aa2a
0a8b91c
315ba88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| import numpy.typing as npt | ||
| from typing_extensions import deprecated | ||
|
|
||
| from zarr.core.array import Array, AsyncArray, get_array_metadata | ||
| from zarr.core.array import Array, AsyncArray, create_array, get_array_metadata | ||
| from zarr.core.array_spec import ArrayConfig, ArrayConfigParams | ||
| from zarr.core.buffer import NDArrayLike | ||
| from zarr.core.common import ( | ||
|
|
@@ -18,14 +18,14 @@ | |
| ChunkCoords, | ||
| MemoryOrder, | ||
| ZarrFormat, | ||
| _default_zarr_version, | ||
| _warn_order_kwarg, | ||
| _warn_write_empty_chunks_kwarg, | ||
| parse_dtype, | ||
| ) | ||
| from zarr.core.config import config | ||
| from zarr.core.group import AsyncGroup, ConsolidatedMetadata, GroupMetadata | ||
| from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata | ||
| from zarr.core.metadata.v2 import _default_filters_and_compressor | ||
| from zarr.core.metadata.v2 import _default_compressor, _default_filters | ||
| from zarr.errors import NodeTypeValidationError | ||
| from zarr.storage import ( | ||
| StoreLike, | ||
|
|
@@ -49,6 +49,7 @@ | |
| "copy_all", | ||
| "copy_store", | ||
| "create", | ||
| "create_array", | ||
| "empty", | ||
| "empty_like", | ||
| "full", | ||
|
|
@@ -150,11 +151,6 @@ def _handle_zarr_version_or_format( | |
| return zarr_format | ||
|
|
||
|
|
||
| def _default_zarr_version() -> ZarrFormat: | ||
| """Return the default zarr_version""" | ||
| return cast(ZarrFormat, int(config.get("default_zarr_version", 3))) | ||
|
|
||
|
|
||
| async def consolidate_metadata( | ||
| store: StoreLike, | ||
| path: str | None = None, | ||
|
|
@@ -300,8 +296,8 @@ async def open( | |
| path : str or None, optional | ||
| The path within the store to open. | ||
| storage_options : dict | ||
| If using an fsspec URL to create the store, these will be passed to | ||
| the backend implementation. Ignored otherwise. | ||
| If the store is backed by an fsspec-based implementation, then this dict will be passed to | ||
| the Store constructor for that implementation. Ignored otherwise. | ||
| **kwargs | ||
| Additional parameters are passed through to :func:`zarr.creation.open_array` or | ||
| :func:`zarr.hierarchy.open_group`. | ||
|
|
@@ -666,6 +662,54 @@ async def group( | |
| ) | ||
|
|
||
|
|
||
| async def create_group( | ||
| *, | ||
| store: StoreLike, | ||
| path: str | None = None, | ||
| overwrite: bool = False, | ||
| zarr_format: ZarrFormat | None = None, | ||
| attributes: dict[str, Any] | None = None, | ||
| storage_options: dict[str, Any] | None = None, | ||
| ) -> AsyncGroup: | ||
| """Create a group. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| store : Store or str | ||
| Store or path to directory in file system. | ||
| path : str, optional | ||
| Group path within store. | ||
| overwrite : bool, optional | ||
| If True, pre-existing data at ``path`` will be deleted before | ||
| creating the group. | ||
| zarr_format : {2, 3, None}, optional | ||
| The zarr format to use when saving. | ||
| storage_options : dict | ||
| If using an fsspec URL to create the store, these will be passed to | ||
| the backend implementation. Ignored otherwise. | ||
|
|
||
| Returns | ||
| ------- | ||
| g : group | ||
| The new group. | ||
| """ | ||
|
|
||
| if zarr_format is None: | ||
| zarr_format = _default_zarr_version() | ||
|
|
||
| # TODO: fix this when modes make sense. It should be `w` for overwriting, `w-` otherwise | ||
d-v-b marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| mode: Literal["a"] = "a" | ||
|
||
|
|
||
| store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) | ||
|
|
||
| return await AsyncGroup.from_store( | ||
| store=store_path, | ||
| zarr_format=zarr_format, | ||
| overwrite=overwrite, | ||
| attributes=attributes, | ||
| ) | ||
|
|
||
|
|
||
| async def open_group( | ||
| store: StoreLike | None = None, | ||
| *, # Note: this is a change from v2 | ||
|
|
@@ -843,8 +887,8 @@ async def create( | |
| If no codecs are provided, default codecs will be used: | ||
|
|
||
| - For numeric arrays, the default is ``BytesCodec`` and ``ZstdCodec``. | ||
| - For Unicode strings, the default is ``VLenUTF8Codec``. | ||
| - For bytes or objects, the default is ``VLenBytesCodec``. | ||
| - For Unicode strings, the default is ``VLenUTF8Codec`` and ``ZstdCodec``. | ||
| - For bytes or objects, the default is ``VLenBytesCodec`` and ``ZstdCodec``. | ||
|
|
||
| These defaults can be changed by modifying the value of ``array.v3_default_codecs`` in :mod:`zarr.core.config`. | ||
| compressor : Codec, optional | ||
|
|
@@ -857,7 +901,8 @@ async def create( | |
| - For Unicode strings, the default is ``VLenUTF8Codec``. | ||
| - For bytes or objects, the default is ``VLenBytesCodec``. | ||
|
|
||
| These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. fill_value : object | ||
| These defaults can be changed by modifying the value of ``array.v2_default_compressor`` in :mod:`zarr.core.config`. | ||
| fill_value : object | ||
| Default value to use for uninitialized portions of the array. | ||
| order : {'C', 'F'}, optional | ||
| Deprecated in favor of the ``config`` keyword argument. | ||
|
|
@@ -878,8 +923,8 @@ async def create( | |
| for storage of both chunks and metadata. | ||
| filters : sequence of Codecs, optional | ||
| Sequence of filters to use to encode chunk data prior to compression. | ||
| V2 only. If neither ``compressor`` nor ``filters`` are provided, a default | ||
| compressor will be used. (see ``compressor`` for details). | ||
| V2 only. If no ``filters`` are provided, a default set of filters will be used. | ||
| These defaults can be changed by modifying the value of ``array.v2_default_filters`` in :mod:`zarr.core.config`. | ||
| cache_metadata : bool, optional | ||
| If True, array configuration metadata will be cached for the | ||
| lifetime of the object. If False, array metadata will be reloaded | ||
|
|
@@ -932,8 +977,10 @@ async def create( | |
| if chunks is None: | ||
| chunks = shape | ||
| dtype = parse_dtype(dtype, zarr_format) | ||
| if not filters and not compressor: | ||
| filters, compressor = _default_filters_and_compressor(dtype) | ||
| if not filters: | ||
| filters = _default_filters(dtype) | ||
| if not compressor: | ||
| compressor = _default_compressor(dtype) | ||
| elif zarr_format == 3 and chunk_shape is None: # type: ignore[redundant-expr] | ||
| if chunks is not None: | ||
| chunk_shape = chunks | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.