Skip to content

Commit 40bc156

Browse files
authored
Merge branch 'main' into avoid-mem-copy-in-obstore-write
2 parents a48b8bd + 018f61d commit 40bc156

26 files changed

+973
-117
lines changed

changes/2622.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``zarr.from_array`` using concurrent streaming of source data

changes/2714.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make warning filters in the tests more specific, so warnings emitted by tests added in the future are more likely to be caught instead of ignored.

changes/2718.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
0-dimensional arrays are now returning a scalar. Therefore, the return type of ``__getitem__`` changed
2+
to NDArrayLikeOrScalar. This change is to make the behavior of 0-dimensional arrays consistent with
3+
``numpy`` scalars.

docs/release-notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ Other
145145
3.0.1 (Jan. 17, 2025)
146146
---------------------
147147

148+
* Implement ``zarr.from_array`` using concurrent streaming (:issue:`2622`).
149+
148150
Bug fixes
149151
~~~~~~~~~
150152
* Fixes ``order`` argument for Zarr format 2 arrays (:issue:`2679`).

pyproject.toml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,18 @@ addopts = [
397397
"--durations=10", "-ra", "--strict-config", "--strict-markers",
398398
]
399399
filterwarnings = [
400-
"error:::zarr.*",
401-
"ignore:PY_SSIZE_T_CLEAN will be required.*:DeprecationWarning",
402-
"ignore:The loop argument is deprecated since Python 3.8.*:DeprecationWarning",
403-
"ignore:Creating a zarr.buffer.gpu.*:UserWarning",
404-
"ignore:Duplicate name:UserWarning", # from ZipFile
405-
"ignore:.*is currently not part in the Zarr format 3 specification.*:UserWarning",
400+
"error",
401+
# TODO: explicitly filter or catch the warnings below where we expect them to be emitted in the tests
402+
"ignore:Consolidated metadata is currently not part in the Zarr format 3 specification.*:UserWarning",
403+
"ignore:Creating a zarr.buffer.gpu.Buffer with an array that does not support the __cuda_array_interface__.*:UserWarning",
404+
"ignore:Automatic shard shape inference is experimental and may change without notice.*:UserWarning",
405+
"ignore:The codec .* is currently not part in the Zarr format 3 specification.*:UserWarning",
406+
"ignore:The dtype .* is currently not part in the Zarr format 3 specification.*:UserWarning",
407+
"ignore:Use zarr.create_array instead.:DeprecationWarning",
408+
"ignore:Duplicate name.*:UserWarning",
409+
"ignore:The `compressor` argument is deprecated. Use `compressors` instead.:UserWarning",
410+
"ignore:Numcodecs codecs are not in the Zarr version 3 specification and may not be supported by other zarr implementations.:UserWarning",
411+
"ignore:Unclosed client session <aiohttp.client.ClientSession.*:ResourceWarning"
406412
]
407413
markers = [
408414
"gpu: mark a test as requiring CuPy and GPU",

src/zarr/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
create_hierarchy,
1212
empty,
1313
empty_like,
14+
from_array,
1415
full,
1516
full_like,
1617
group,
@@ -54,6 +55,7 @@
5455
"create_hierarchy",
5556
"empty",
5657
"empty_like",
58+
"from_array",
5759
"full",
5860
"full_like",
5961
"group",

src/zarr/api/asynchronous.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy.typing as npt
1010
from typing_extensions import deprecated
1111

12-
from zarr.core.array import Array, AsyncArray, create_array, get_array_metadata
12+
from zarr.core.array import Array, AsyncArray, create_array, from_array, get_array_metadata
1313
from zarr.core.array_spec import ArrayConfig, ArrayConfigLike, ArrayConfigParams
1414
from zarr.core.buffer import NDArrayLike
1515
from zarr.core.common import (
@@ -38,6 +38,7 @@
3838
from collections.abc import Iterable
3939

4040
from zarr.abc.codec import Codec
41+
from zarr.core.buffer import NDArrayLikeOrScalar
4142
from zarr.core.chunk_key_encodings import ChunkKeyEncoding
4243
from zarr.storage import StoreLike
4344

@@ -56,6 +57,7 @@
5657
"create_hierarchy",
5758
"empty",
5859
"empty_like",
60+
"from_array",
5961
"full",
6062
"full_like",
6163
"group",
@@ -238,7 +240,7 @@ async def load(
238240
path: str | None = None,
239241
zarr_format: ZarrFormat | None = None,
240242
zarr_version: ZarrFormat | None = None,
241-
) -> NDArrayLike | dict[str, NDArrayLike]:
243+
) -> NDArrayLikeOrScalar | dict[str, NDArrayLikeOrScalar]:
242244
"""Load data from an array or group into memory.
243245
244246
Parameters
@@ -533,7 +535,7 @@ async def tree(grp: AsyncGroup, expand: bool | None = None, level: int | None =
533535

534536

535537
async def array(
536-
data: npt.ArrayLike, **kwargs: Any
538+
data: npt.ArrayLike | Array, **kwargs: Any
537539
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
538540
"""Create an array filled with `data`.
539541
@@ -550,13 +552,16 @@ async def array(
550552
The new array.
551553
"""
552554

555+
if isinstance(data, Array):
556+
return await from_array(data=data, **kwargs)
557+
553558
# ensure data is array-like
554559
if not hasattr(data, "shape") or not hasattr(data, "dtype"):
555560
data = np.asanyarray(data)
556561

557562
# setup dtype
558563
kw_dtype = kwargs.get("dtype")
559-
if kw_dtype is None:
564+
if kw_dtype is None and hasattr(data, "dtype"):
560565
kwargs["dtype"] = data.dtype
561566
else:
562567
kwargs["dtype"] = kw_dtype

0 commit comments

Comments
 (0)