Skip to content

Commit 5544885

Browse files
authored
Merge branch 'main' into store-docstrings
2 parents b6e697f + bb55f0c commit 5544885

29 files changed

+989
-143
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
run: |
6565
hatch env run --env test.py${{ matrix.python-version }}-${{ matrix.numpy-version }}-${{ matrix.dependency-set }} run-coverage
6666
- name: Upload coverage
67+
if: ${{ matrix.dependency-set == 'optional' && matrix.os == 'ubuntu-latest' }}
6768
uses: codecov/codecov-action@v5
6869
with:
6970
token: ${{ secrets.CODECOV_TOKEN }}

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/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.

changes/2991.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Updated the 3.0 migration guide to include the removal of "." syntax for getting group members.

changes/2996.bugfix.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fixes `ConsolidatedMetadata` serialization of `nan`, `inf`, and `-inf` to be
2+
consistent with the behavior of `ArrayMetadata`.
3+
4+

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`).

docs/user-guide/v3_migration.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ The Group class
117117

118118
- Use :func:`zarr.Group.create_array` in place of :func:`zarr.Group.create_dataset`
119119
- Use :func:`zarr.Group.require_array` in place of :func:`zarr.Group.require_dataset`
120+
3. Disallow "." syntax for getting group members. To get a member of a group named ``foo``,
121+
use ``group["foo"]`` in place of ``group.foo``.
120122

121123
The Store class
122124
~~~~~~~~~~~~~~~

pyproject.toml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,19 @@ gpu = [
7373
test = [
7474
"coverage",
7575
"pytest",
76+
"pytest-asyncio",
7677
"pytest-cov",
78+
"pytest-accept",
79+
"rich",
80+
"mypy",
81+
"hypothesis",
82+
]
83+
remote_tests = [
7784
'zarr[remote]',
7885
"botocore",
7986
"s3fs",
8087
"moto[s3,server]",
81-
"pytest-asyncio",
82-
"pytest-accept",
8388
"requests",
84-
"rich",
85-
"mypy",
86-
"hypothesis",
87-
"universal-pathlib",
8889
]
8990
optional = ["rich", "universal-pathlib"]
9091
docs = [
@@ -143,28 +144,21 @@ hooks.vcs.version-file = "src/zarr/_version.py"
143144
[tool.hatch.envs.test]
144145
dependencies = [
145146
"numpy~={matrix:numpy}",
146-
"universal_pathlib",
147147
]
148148
features = ["test"]
149149

150150
[[tool.hatch.envs.test.matrix]]
151151
python = ["3.11", "3.12", "3.13"]
152152
numpy = ["1.25", "2.1"]
153-
version = ["minimal"]
154-
155-
[[tool.hatch.envs.test.matrix]]
156-
python = ["3.11", "3.12", "3.13"]
157-
numpy = ["1.25", "2.1"]
158-
features = ["optional"]
153+
deps = ["minimal", "optional"]
159154

160-
[[tool.hatch.envs.test.matrix]]
161-
python = ["3.11", "3.12", "3.13"]
162-
numpy = ["1.25", "2.1"]
163-
features = ["gpu"]
155+
[tool.hatch.envs.test.overrides]
156+
matrix.deps.dependencies = [
157+
{value = "zarr[remote, remote_tests, test, optional]", if = ["optional"]}
158+
]
164159

165160
[tool.hatch.envs.test.scripts]
166161
run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov-report xml --cov=src --junitxml=junit.xml -o junit_family=legacy"
167-
run-coverage-gpu = "pip install cupy-cuda12x && pytest -m gpu --cov-config=pyproject.toml --cov=pkg --cov-report xml --cov=src --junitxml=junit.xml -o junit_family=legacy"
168162
run-coverage-html = "pytest --cov-config=pyproject.toml --cov=pkg --cov-report html --cov=src"
169163
run = "run-coverage --no-cov"
170164
run-pytest = "run"
@@ -174,7 +168,7 @@ run-hypothesis = "run-coverage --hypothesis-profile ci --run-slow-hypothesis tes
174168
list-env = "pip list"
175169

176170
[tool.hatch.envs.doctest]
177-
features = ["test", "optional", "remote"]
171+
features = ["test", "optional", "remote", "remote_tests"]
178172
description = "Test environment for doctests"
179173

180174
[tool.hatch.envs.doctest.scripts]
@@ -255,6 +249,7 @@ dependencies = [
255249
'universal_pathlib==0.0.22',
256250
'typing_extensions==4.9.*',
257251
'donfig==0.8.*',
252+
'obstore==0.5.*',
258253
# test deps
259254
'zarr[test]',
260255
]

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)