Skip to content

Commit b977cff

Browse files
authored
Merge branch 'main' into fix/remote-store-path
2 parents c094891 + a9d6d74 commit b977cff

File tree

12 files changed

+177
-53
lines changed

12 files changed

+177
-53
lines changed

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,35 @@ jobs:
4343
- name: Run Tests
4444
run: |
4545
hatch env run --env test.py${{ matrix.python-version }}-${{ matrix.numpy-version }}-${{ matrix.dependency-set }} run
46+
47+
test-upstream-and-min-deps:
48+
name: py=${{ matrix.python-version }}-${{ matrix.dependency-set }}
49+
50+
runs-on: ubuntu-latest
51+
strategy:
52+
matrix:
53+
python-version: ['3.11', "3.13"]
54+
dependency-set: ["upstream", "min_deps"]
55+
exclude:
56+
- python-version: "3.13"
57+
dependency-set: min_deps
58+
- python-version: "3.11"
59+
dependency-set: upstream
60+
steps:
61+
- uses: actions/checkout@v4
62+
- name: Set up Python
63+
uses: actions/setup-python@v5
64+
with:
65+
python-version: ${{ matrix.python-version }}
66+
cache: 'pip'
67+
- name: Install Hatch
68+
run: |
69+
python -m pip install --upgrade pip
70+
pip install hatch
71+
- name: Set Up Hatch Env
72+
run: |
73+
hatch env create ${{ matrix.dependency-set }}
74+
hatch env run -e ${{ matrix.dependency-set }} list-env
75+
- name: Run Tests
76+
run: |
77+
hatch env run --env ${{ matrix.dependency-set }} run

.pep8speaks.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

pyproject.toml

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ requires-python = ">=3.11"
2828
dependencies = [
2929
'asciitree',
3030
'numpy>=1.25',
31-
'numcodecs>=0.10.2',
32-
'fsspec>2024',
33-
'crc32c',
34-
'typing_extensions',
35-
'donfig',
31+
'numcodecs>=0.13',
32+
'fsspec>=2022.10.0',
33+
'crc32c>=2.3',
34+
'typing_extensions>=4.6',
35+
'donfig>=0.8',
3636
]
37+
3738
dynamic = [
3839
"version",
3940
]
@@ -98,7 +99,7 @@ extra = [
9899
]
99100
optional = [
100101
'lmdb',
101-
'universal-pathlib',
102+
'universal-pathlib>=0.0.22',
102103
]
103104

104105
[project.urls]
@@ -183,6 +184,65 @@ features = ['docs']
183184
build = "cd docs && make html"
184185
serve = "sphinx-autobuild docs docs/_build --host 0.0.0.0"
185186

187+
[tool.hatch.envs.upstream]
188+
python = "3.13"
189+
dependencies = [
190+
'numpy', # from scientific-python-nightly-wheels
191+
'numcodecs @ git+https://github.com/zarr-developers/numcodecs',
192+
'fsspec @ git+https://github.com/fsspec/filesystem_spec',
193+
's3fs @ git+https://github.com/fsspec/s3fs',
194+
'universal_pathlib @ git+https://github.com/fsspec/universal_pathlib',
195+
'crc32c @ git+https://github.com/ICRAR/crc32c',
196+
'typing_extensions @ git+https://github.com/python/typing_extensions',
197+
'donfig @ git+https://github.com/pytroll/donfig',
198+
# test deps
199+
'hypothesis',
200+
'pytest',
201+
'pytest-cov',
202+
'pytest-asyncio',
203+
'moto[s3]',
204+
]
205+
206+
[tool.hatch.envs.upstream.env-vars]
207+
PIP_INDEX_URL = "https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/"
208+
PIP_EXTRA_INDEX_URL = "https://pypi.org/simple/"
209+
PIP_PRE = "1"
210+
211+
[tool.hatch.envs.upstream.scripts]
212+
run = "pytest --verbose"
213+
run-mypy = "mypy src"
214+
run-hypothesis = "pytest --hypothesis-profile ci tests/test_properties.py tests/test_store/test_stateful*"
215+
list-env = "pip list"
216+
217+
[tool.hatch.envs.min_deps]
218+
description = """Test environment for minimum supported dependencies
219+
220+
See Spec 0000 for details and drop schedule: https://scientific-python.org/specs/spec-0000/
221+
"""
222+
python = "3.11"
223+
dependencies = [
224+
'numpy==1.25.*',
225+
'numcodecs==0.13.*', # 0.13 needed for? (should be 0.11)
226+
'fsspec==2022.10.0',
227+
's3fs==2022.10.0',
228+
'universal_pathlib==0.0.22',
229+
'crc32c==2.3.*',
230+
'typing_extensions==4.6.*', # 4.5 needed for @deprecated, 4.6 for Buffer
231+
'donfig==0.8.*',
232+
# test deps
233+
'hypothesis',
234+
'pytest',
235+
'pytest-cov',
236+
'pytest-asyncio',
237+
'moto[s3]',
238+
]
239+
240+
[tool.hatch.envs.min_deps.scripts]
241+
run = "pytest --verbose"
242+
run-hypothesis = "pytest --hypothesis-profile ci tests/test_properties.py tests/test_store/test_stateful*"
243+
list-env = "pip list"
244+
245+
186246
[tool.ruff]
187247
line-length = 100
188248
force-exclude = true

src/zarr/api/asynchronous.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ async def create(
712712
dtype: npt.DTypeLike | None = None,
713713
compressor: dict[str, JSON] | None = None, # TODO: default and type change
714714
fill_value: Any | None = 0, # TODO: need type
715-
order: MemoryOrder | None = None, # TODO: default change
715+
order: MemoryOrder | None = None,
716716
store: str | StoreLike | None = None,
717717
synchronizer: Any | None = None,
718718
overwrite: bool = False,
@@ -761,6 +761,7 @@ async def create(
761761
Default value to use for uninitialized portions of the array.
762762
order : {'C', 'F'}, optional
763763
Memory layout to be used within each chunk.
764+
Default is set in Zarr's config (`array.order`).
764765
store : Store or str
765766
Store or path to directory in file system or name of zip file.
766767
synchronizer : object, optional
@@ -834,12 +835,6 @@ async def create(
834835
else:
835836
chunk_shape = shape
836837

837-
if order is not None:
838-
warnings.warn(
839-
"order is deprecated, use config `array.order` instead",
840-
DeprecationWarning,
841-
stacklevel=2,
842-
)
843838
if synchronizer is not None:
844839
warnings.warn("synchronizer is not yet implemented", RuntimeWarning, stacklevel=2)
845840
if chunk_store is not None:
@@ -889,6 +884,7 @@ async def create(
889884
codecs=codecs,
890885
dimension_names=dimension_names,
891886
attributes=attributes,
887+
order=order,
892888
**kwargs,
893889
)
894890

src/zarr/codecs/zstd.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import asyncio
44
from dataclasses import dataclass
55
from functools import cached_property
6-
from importlib.metadata import version
76
from typing import TYPE_CHECKING
87

8+
import numcodecs
99
from numcodecs.zstd import Zstd
10+
from packaging.version import Version
1011

1112
from zarr.abc.codec import BytesBytesCodec
1213
from zarr.core.buffer.cpu import as_numpy_array_wrapper
@@ -43,8 +44,8 @@ class ZstdCodec(BytesBytesCodec):
4344

4445
def __init__(self, *, level: int = 0, checksum: bool = False) -> None:
4546
# numcodecs 0.13.0 introduces the checksum attribute for the zstd codec
46-
_numcodecs_version = tuple(map(int, version("numcodecs").split(".")))
47-
if _numcodecs_version < (0, 13, 0): # pragma: no cover
47+
_numcodecs_version = Version(numcodecs.__version__)
48+
if _numcodecs_version < Version("0.13.0"):
4849
raise RuntimeError(
4950
"numcodecs version >= 0.13.0 is required to use the zstd codec. "
5051
f"Version {_numcodecs_version} is currently installed."

src/zarr/core/array.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
ZARRAY_JSON,
3434
ZATTRS_JSON,
3535
ChunkCoords,
36+
MemoryOrder,
3637
ShapeLike,
3738
ZarrFormat,
3839
concurrent_map,
@@ -203,29 +204,29 @@ class AsyncArray(Generic[T_ArrayMetadata]):
203204
metadata: T_ArrayMetadata
204205
store_path: StorePath
205206
codec_pipeline: CodecPipeline = field(init=False)
206-
order: Literal["C", "F"]
207+
order: MemoryOrder
207208

208209
@overload
209210
def __init__(
210211
self: AsyncArray[ArrayV2Metadata],
211212
metadata: ArrayV2Metadata | ArrayV2MetadataDict,
212213
store_path: StorePath,
213-
order: Literal["C", "F"] | None = None,
214+
order: MemoryOrder | None = None,
214215
) -> None: ...
215216

216217
@overload
217218
def __init__(
218219
self: AsyncArray[ArrayV3Metadata],
219220
metadata: ArrayV3Metadata | ArrayV3MetadataDict,
220221
store_path: StorePath,
221-
order: Literal["C", "F"] | None = None,
222+
order: MemoryOrder | None = None,
222223
) -> None: ...
223224

224225
def __init__(
225226
self,
226227
metadata: ArrayMetadata | ArrayMetadataDict,
227228
store_path: StorePath,
228-
order: Literal["C", "F"] | None = None,
229+
order: MemoryOrder | None = None,
229230
) -> None:
230231
if isinstance(metadata, dict):
231232
zarr_format = metadata["zarr_format"]
@@ -261,7 +262,7 @@ async def create(
261262
attributes: dict[str, JSON] | None = None,
262263
chunks: ShapeLike | None = None,
263264
dimension_separator: Literal[".", "/"] | None = None,
264-
order: Literal["C", "F"] | None = None,
265+
order: MemoryOrder | None = None,
265266
filters: list[dict[str, JSON]] | None = None,
266267
compressor: dict[str, JSON] | None = None,
267268
# runtime
@@ -350,7 +351,7 @@ async def create(
350351
# v2 only
351352
chunks: ShapeLike | None = None,
352353
dimension_separator: Literal[".", "/"] | None = None,
353-
order: Literal["C", "F"] | None = None,
354+
order: MemoryOrder | None = None,
354355
filters: list[dict[str, JSON]] | None = None,
355356
compressor: dict[str, JSON] | None = None,
356357
# runtime
@@ -382,7 +383,7 @@ async def create(
382383
# v2 only
383384
chunks: ShapeLike | None = None,
384385
dimension_separator: Literal[".", "/"] | None = None,
385-
order: Literal["C", "F"] | None = None,
386+
order: MemoryOrder | None = None,
386387
filters: list[dict[str, JSON]] | None = None,
387388
compressor: dict[str, JSON] | None = None,
388389
# runtime
@@ -422,7 +423,6 @@ async def create(
422423
V2 only. V3 arrays cannot have a dimension separator.
423424
order : Literal["C", "F"], optional
424425
The order of the array (default is None).
425-
V2 only. V3 arrays should not have 'order' parameter.
426426
filters : list[dict[str, JSON]], optional
427427
The filters used to compress the data (default is None).
428428
V2 only. V3 arrays should not have 'filters' parameter.
@@ -471,10 +471,6 @@ async def create(
471471
raise ValueError(
472472
"dimension_separator cannot be used for arrays with version 3. Use chunk_key_encoding instead."
473473
)
474-
if order is not None:
475-
raise ValueError(
476-
"order cannot be used for arrays with version 3. Use a transpose codec instead."
477-
)
478474
if filters is not None:
479475
raise ValueError(
480476
"filters cannot be used for arrays with version 3. Use array-to-array codecs instead."
@@ -494,6 +490,7 @@ async def create(
494490
dimension_names=dimension_names,
495491
attributes=attributes,
496492
exists_ok=exists_ok,
493+
order=order,
497494
)
498495
elif zarr_format == 2:
499496
if dtype is str or dtype == "str":
@@ -545,6 +542,7 @@ async def _create_v3(
545542
dtype: npt.DTypeLike,
546543
chunk_shape: ChunkCoords,
547544
fill_value: Any | None = None,
545+
order: MemoryOrder | None = None,
548546
chunk_key_encoding: (
549547
ChunkKeyEncoding
550548
| tuple[Literal["default"], Literal[".", "/"]]
@@ -588,7 +586,7 @@ async def _create_v3(
588586
attributes=attributes or {},
589587
)
590588

591-
array = cls(metadata=metadata, store_path=store_path)
589+
array = cls(metadata=metadata, store_path=store_path, order=order)
592590
await array._save_metadata(metadata, ensure_parents=True)
593591
return array
594592

@@ -602,16 +600,17 @@ async def _create_v2(
602600
chunks: ChunkCoords,
603601
dimension_separator: Literal[".", "/"] | None = None,
604602
fill_value: None | float = None,
605-
order: Literal["C", "F"] | None = None,
603+
order: MemoryOrder | None = None,
606604
filters: list[dict[str, JSON]] | None = None,
607605
compressor: dict[str, JSON] | None = None,
608606
attributes: dict[str, JSON] | None = None,
609607
exists_ok: bool = False,
610608
) -> AsyncArray[ArrayV2Metadata]:
611609
if not exists_ok:
612610
await ensure_no_existing_node(store_path, zarr_format=2)
611+
613612
if order is None:
614-
order = "C"
613+
order = parse_indexing_order(config.get("array.order"))
615614

616615
if dimension_separator is None:
617616
dimension_separator = "."
@@ -627,7 +626,7 @@ async def _create_v2(
627626
filters=filters,
628627
attributes=attributes,
629628
)
630-
array = cls(metadata=metadata, store_path=store_path)
629+
array = cls(metadata=metadata, store_path=store_path, order=order)
631630
await array._save_metadata(metadata, ensure_parents=True)
632631
return array
633632

@@ -1179,7 +1178,7 @@ def create(
11791178
# v2 only
11801179
chunks: ChunkCoords | None = None,
11811180
dimension_separator: Literal[".", "/"] | None = None,
1182-
order: Literal["C", "F"] | None = None,
1181+
order: MemoryOrder | None = None,
11831182
filters: list[dict[str, JSON]] | None = None,
11841183
compressor: dict[str, JSON] | None = None,
11851184
# runtime
@@ -1370,7 +1369,7 @@ def store_path(self) -> StorePath:
13701369
return self._async_array.store_path
13711370

13721371
@property
1373-
def order(self) -> Literal["C", "F"]:
1372+
def order(self) -> MemoryOrder:
13741373
return self._async_array.order
13751374

13761375
@property

src/zarr/core/array_spec.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass
4-
from typing import TYPE_CHECKING, Any, Literal
4+
from typing import TYPE_CHECKING, Any
55

66
import numpy as np
77

8-
from zarr.core.common import parse_fill_value, parse_order, parse_shapelike
8+
from zarr.core.common import MemoryOrder, parse_fill_value, parse_order, parse_shapelike
99

1010
if TYPE_CHECKING:
1111
from zarr.core.buffer import BufferPrototype
@@ -17,15 +17,15 @@ class ArraySpec:
1717
shape: ChunkCoords
1818
dtype: np.dtype[Any]
1919
fill_value: Any
20-
order: Literal["C", "F"]
20+
order: MemoryOrder
2121
prototype: BufferPrototype
2222

2323
def __init__(
2424
self,
2525
shape: ChunkCoords,
2626
dtype: np.dtype[Any],
2727
fill_value: Any,
28-
order: Literal["C", "F"],
28+
order: MemoryOrder,
2929
prototype: BufferPrototype,
3030
) -> None:
3131
shape_parsed = parse_shapelike(shape)

0 commit comments

Comments
 (0)