Skip to content

Commit 947f20e

Browse files
committed
tweaks
1 parent 305fdb7 commit 947f20e

File tree

5 files changed

+268
-29
lines changed

5 files changed

+268
-29
lines changed

src/zarr/api/asynchronous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ async def open_array(
12201220
If using an fsspec URL to create the store, these will be passed to
12211221
the backend implementation. Ignored otherwise.
12221222
**kwargs
1223-
Any keyword arguments to pass to ``create``.
1223+
Any keyword arguments to pass to :func:`create`.
12241224
12251225
Returns
12261226
-------

src/zarr/core/array.py

Lines changed: 149 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@
77
from dataclasses import dataclass, field
88
from itertools import starmap
99
from logging import getLogger
10-
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeAlias, TypedDict, cast, overload
10+
from typing import (
11+
TYPE_CHECKING,
12+
Any,
13+
Generic,
14+
Literal,
15+
TypeAlias,
16+
TypedDict,
17+
cast,
18+
overload,
19+
)
1120
from warnings import warn
1221

1322
import numcodecs
1423
import numpy as np
1524
import numpy.typing as npt
25+
from typing_extensions import deprecated
1626

1727
from zarr._compat import _deprecate_positional_args
1828
from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec, BytesBytesCodec, Codec
@@ -274,7 +284,7 @@ def __init__(
274284
# this overload defines the function signature when zarr_format is 2
275285
@overload
276286
@classmethod
277-
async def _create(
287+
async def create(
278288
cls,
279289
store: StoreLike,
280290
*,
@@ -298,7 +308,7 @@ async def _create(
298308
# this overload defines the function signature when zarr_format is 3
299309
@overload
300310
@classmethod
301-
async def _create(
311+
async def create(
302312
cls,
303313
store: StoreLike,
304314
*,
@@ -326,7 +336,7 @@ async def _create(
326336

327337
@overload
328338
@classmethod
329-
async def _create(
339+
async def create(
330340
cls,
331341
store: StoreLike,
332342
*,
@@ -351,9 +361,10 @@ async def _create(
351361
data: npt.ArrayLike | None = None,
352362
config: ArrayConfig | ArrayConfigParams | None = None,
353363
) -> AsyncArray[ArrayV3Metadata]: ...
364+
354365
@overload
355366
@classmethod
356-
async def _create(
367+
async def create(
357368
cls,
358369
store: StoreLike,
359370
*,
@@ -386,8 +397,9 @@ async def _create(
386397
) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]: ...
387398

388399
@classmethod
389-
# @deprecated("Use `zarr.api.asynchronous.create_array` instead.")
390-
async def _create(
400+
@deprecated("Use zarr.api.asynchronous.create_array instead.")
401+
@_deprecate_positional_args
402+
async def create(
391403
cls,
392404
store: StoreLike,
393405
*,
@@ -418,9 +430,7 @@ async def _create(
418430
data: npt.ArrayLike | None = None,
419431
config: ArrayConfig | ArrayConfigParams | None = None,
420432
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
421-
"""
422-
Deprecated in favor of `zarr.api.asynchronous.create_array`.
423-
Method to create a new asynchronous array instance.
433+
"""Method to create a new asynchronous array instance.
424434
425435
Parameters
426436
----------
@@ -499,6 +509,70 @@ async def _create(
499509
-------
500510
AsyncArray
501511
The created asynchronous array instance.
512+
513+
.. deprecated:: 3.0.0
514+
Deprecated in favor of :func:`zarr.api.asynchronous.create_array`.
515+
"""
516+
return await cls._create(
517+
store,
518+
# v2 and v3
519+
shape=shape,
520+
dtype=dtype,
521+
zarr_format=zarr_format,
522+
fill_value=fill_value,
523+
attributes=attributes,
524+
# v3 only
525+
chunk_shape=chunk_shape,
526+
chunk_key_encoding=chunk_key_encoding,
527+
codecs=codecs,
528+
dimension_names=dimension_names,
529+
# v2 only
530+
chunks=chunks,
531+
dimension_separator=dimension_separator,
532+
order=order,
533+
filters=filters,
534+
compressor=compressor,
535+
# runtime
536+
overwrite=overwrite,
537+
data=data,
538+
config=config,
539+
)
540+
541+
@classmethod
542+
async def _create(
543+
cls,
544+
store: StoreLike,
545+
*,
546+
# v2 and v3
547+
shape: ShapeLike,
548+
dtype: npt.DTypeLike,
549+
zarr_format: ZarrFormat = 3,
550+
fill_value: Any | None = None,
551+
attributes: dict[str, JSON] | None = None,
552+
# v3 only
553+
chunk_shape: ShapeLike | None = None,
554+
chunk_key_encoding: (
555+
ChunkKeyEncoding
556+
| tuple[Literal["default"], Literal[".", "/"]]
557+
| tuple[Literal["v2"], Literal[".", "/"]]
558+
| None
559+
) = None,
560+
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
561+
dimension_names: Iterable[str] | None = None,
562+
# v2 only
563+
chunks: ShapeLike | None = None,
564+
dimension_separator: Literal[".", "/"] | None = None,
565+
order: MemoryOrder | None = None,
566+
filters: list[dict[str, JSON]] | None = None,
567+
compressor: dict[str, JSON] | None = None,
568+
# runtime
569+
overwrite: bool = False,
570+
data: npt.ArrayLike | None = None,
571+
config: ArrayConfig | ArrayConfigParams | None = None,
572+
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
573+
"""Method to create a new asynchronous array instance.
574+
See :func:`AsyncArray.create` for more details.
575+
Deprecated in favor of :func:`zarr.api.asynchronous.create_array`.
502576
"""
503577
store_path = await make_store_path(store)
504578

@@ -1529,9 +1603,9 @@ class Array:
15291603
_async_array: AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]
15301604

15311605
@classmethod
1532-
# @deprecated("Use `zarr.create_array` instead.")
1606+
@deprecated("Use zarr.create_array instead.")
15331607
@_deprecate_positional_args
1534-
def _create(
1608+
def create(
15351609
cls,
15361610
store: StoreLike,
15371611
*,
@@ -1561,8 +1635,7 @@ def _create(
15611635
overwrite: bool = False,
15621636
config: ArrayConfig | ArrayConfigParams | None = None,
15631637
) -> Array:
1564-
"""Deprecated in favor of `zarr.create_array`.
1565-
Creates a new Array instance from an initialized store.
1638+
"""Creates a new Array instance from an initialized store.
15661639
15671640
Parameters
15681641
----------
@@ -1631,6 +1704,68 @@ def _create(
16311704
-------
16321705
Array
16331706
Array created from the store.
1707+
1708+
.. deprecated:: 3.0.0
1709+
Deprecated in favor of :func:`zarr.create_array`.
1710+
"""
1711+
return cls._create(
1712+
store,
1713+
# v2 and v3
1714+
shape=shape,
1715+
dtype=dtype,
1716+
zarr_format=zarr_format,
1717+
attributes=attributes,
1718+
fill_value=fill_value,
1719+
# v3 only
1720+
chunk_shape=chunk_shape,
1721+
chunk_key_encoding=chunk_key_encoding,
1722+
codecs=codecs,
1723+
dimension_names=dimension_names,
1724+
# v2 only
1725+
chunks=chunks,
1726+
dimension_separator=dimension_separator,
1727+
order=order,
1728+
filters=filters,
1729+
compressor=compressor,
1730+
# runtime
1731+
overwrite=overwrite,
1732+
config=config,
1733+
)
1734+
1735+
@classmethod
1736+
def _create(
1737+
cls,
1738+
store: StoreLike,
1739+
*,
1740+
# v2 and v3
1741+
shape: ChunkCoords,
1742+
dtype: npt.DTypeLike,
1743+
zarr_format: ZarrFormat = 3,
1744+
fill_value: Any | None = None,
1745+
attributes: dict[str, JSON] | None = None,
1746+
# v3 only
1747+
chunk_shape: ChunkCoords | None = None,
1748+
chunk_key_encoding: (
1749+
ChunkKeyEncoding
1750+
| tuple[Literal["default"], Literal[".", "/"]]
1751+
| tuple[Literal["v2"], Literal[".", "/"]]
1752+
| None
1753+
) = None,
1754+
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
1755+
dimension_names: Iterable[str] | None = None,
1756+
# v2 only
1757+
chunks: ChunkCoords | None = None,
1758+
dimension_separator: Literal[".", "/"] | None = None,
1759+
order: MemoryOrder | None = None,
1760+
filters: list[dict[str, JSON]] | None = None,
1761+
compressor: dict[str, JSON] | None = None,
1762+
# runtime
1763+
overwrite: bool = False,
1764+
config: ArrayConfig | ArrayConfigParams | None = None,
1765+
) -> Array:
1766+
"""Creates a new Array instance from an initialized store.
1767+
See :func:`Array.create` for more details.
1768+
Deprecated in favor of :func:`zarr.create_array`.
16341769
"""
16351770
async_array = sync(
16361771
AsyncArray._create(

tests/test_array.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_array_v3_fill_value(store: MemoryStore, fill_value: int, dtype_str: str
220220
def test_create_positional_args_deprecated() -> None:
221221
store = MemoryStore()
222222
with pytest.warns(FutureWarning, match="Pass"):
223-
zarr.Array._create(store, (2, 2), dtype="f8")
223+
zarr.Array.create(store, (2, 2), dtype="f8")
224224

225225

226226
def test_selection_positional_args_deprecated() -> None:
@@ -436,23 +436,31 @@ def test_default_fill_values() -> None:
436436

437437
def test_vlen_errors() -> None:
438438
with pytest.raises(ValueError, match="At least one ArrayBytesCodec is required."):
439-
Array._create(MemoryStore(), shape=5, chunks=5, dtype="<U4", codecs=[])
439+
Array.create(MemoryStore(), shape=5, chunks=5, dtype="<U4", codecs=[])
440440

441441
with pytest.raises(
442442
ValueError,
443443
match="For string dtype, ArrayBytesCodec must be `VLenUTF8Codec`, got `BytesCodec`.",
444444
):
445-
Array._create(MemoryStore(), shape=5, chunks=5, dtype="<U4", codecs=[BytesCodec()])
445+
Array.create(MemoryStore(), shape=5, chunks=5, dtype="<U4", codecs=[BytesCodec()])
446446

447447
with pytest.raises(ValueError, match="Only one ArrayBytesCodec is allowed."):
448-
Array._create(
448+
Array.create(
449449
MemoryStore(),
450450
shape=5,
451451
chunks=5,
452452
dtype="<U4",
453453
codecs=[BytesCodec(), VLenBytesCodec()],
454454
)
455455

456+
with pytest.raises(
457+
ValueError,
458+
match="For string dtype, ArrayBytesCodec must be `VLenUTF8Codec`, got `BytesCodec`.",
459+
):
460+
zarr.create_array(
461+
MemoryStore(), shape=5, chunks=5, dtype="<U4", array_bytes_codec=BytesCodec()
462+
)
463+
456464

457465
@pytest.mark.parametrize("zarr_format", [2, 3])
458466
def test_update_attrs(zarr_format: int) -> None:

0 commit comments

Comments
 (0)