Skip to content

Commit d11bf30

Browse files
committed
Merge remote-tracking branch 'refs/remotes/upstream/main' into default-compressor
2 parents a77fb0d + 122760f commit d11bf30

File tree

23 files changed

+372
-136
lines changed

23 files changed

+372
-136
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
ci:
22
autoupdate_commit_msg: "chore: update pre-commit hooks"
3+
autoupdate_schedule: "monthly"
34
autofix_commit_msg: "style: pre-commit fixes"
45
autofix_prs: false
56
default_stages: [pre-commit, pre-push]
6-
default_language_version:
7-
python: python3
87
repos:
98
- repo: https://github.com/astral-sh/ruff-pre-commit
109
rev: v0.8.2
@@ -16,7 +15,7 @@ repos:
1615
rev: v2.3.0
1716
hooks:
1817
- id: codespell
19-
args: ["-L", "ba,ihs,kake,nd,noe,nwo,te,fo,zar", "-S", "fixture"]
18+
args: ["-L", "fo,ihs,kake,te", "-S", "fixture"]
2019
- repo: https://github.com/pre-commit/pre-commit-hooks
2120
rev: v5.0.0
2221
hooks:

src/zarr/api/asynchronous.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
_OVERWRITE_MODES: tuple[AccessModeLiteral, ...] = ("a", "r+", "w")
7474

7575

76-
def _infer_exists_ok(mode: AccessModeLiteral) -> bool:
76+
def _infer_overwrite(mode: AccessModeLiteral) -> bool:
7777
"""
7878
Check that an ``AccessModeLiteral`` is compatible with overwriting an existing Zarr node.
7979
"""
@@ -416,14 +416,14 @@ async def save_array(
416416
arr = np.array(arr)
417417
shape = arr.shape
418418
chunks = getattr(arr, "chunks", None) # for array-likes with chunks attribute
419-
exists_ok = kwargs.pop("exists_ok", None) or _infer_exists_ok(mode)
419+
overwrite = kwargs.pop("overwrite", None) or _infer_overwrite(mode)
420420
new = await AsyncArray.create(
421421
store_path,
422422
zarr_format=zarr_format,
423423
shape=shape,
424424
dtype=arr.dtype,
425425
chunks=chunks,
426-
exists_ok=exists_ok,
426+
overwrite=overwrite,
427427
**kwargs,
428428
)
429429
await new.setitem(slice(None), arr)
@@ -649,7 +649,7 @@ async def group(
649649
return await AsyncGroup.from_store(
650650
store=store_path,
651651
zarr_format=_zarr_format,
652-
exists_ok=overwrite,
652+
overwrite=overwrite,
653653
attributes=attributes,
654654
)
655655

@@ -755,12 +755,12 @@ async def open_group(
755755
except (KeyError, FileNotFoundError):
756756
pass
757757
if mode in _CREATE_MODES:
758-
exists_ok = _infer_exists_ok(mode)
758+
overwrite = _infer_overwrite(mode)
759759
_zarr_format = zarr_format or _default_zarr_version()
760760
return await AsyncGroup.from_store(
761761
store_path,
762762
zarr_format=_zarr_format,
763-
exists_ok=exists_ok,
763+
overwrite=overwrite,
764764
attributes=attributes,
765765
)
766766
raise FileNotFoundError(f"Unable to find group: {store_path}")
@@ -944,7 +944,7 @@ async def create(
944944
dtype=dtype,
945945
compressor=compressor,
946946
fill_value=fill_value,
947-
exists_ok=overwrite,
947+
overwrite=overwrite,
948948
filters=filters,
949949
dimension_separator=dimension_separator,
950950
zarr_format=zarr_format,
@@ -1131,12 +1131,12 @@ async def open_array(
11311131
return await AsyncArray.open(store_path, zarr_format=zarr_format)
11321132
except FileNotFoundError:
11331133
if not store_path.read_only and mode in _CREATE_MODES:
1134-
exists_ok = _infer_exists_ok(mode)
1134+
overwrite = _infer_overwrite(mode)
11351135
_zarr_format = zarr_format or _default_zarr_version()
11361136
return await create(
11371137
store=store_path,
11381138
zarr_format=_zarr_format,
1139-
overwrite=exists_ok,
1139+
overwrite=overwrite,
11401140
**kwargs,
11411141
)
11421142
raise

src/zarr/core/array.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ async def create(
267267
filters: list[dict[str, JSON]] | None = None,
268268
compressor: dict[str, JSON] | None = None,
269269
# runtime
270-
exists_ok: bool = False,
270+
overwrite: bool = False,
271271
data: npt.ArrayLike | None = None,
272272
) -> AsyncArray[ArrayV2Metadata]: ...
273273

@@ -295,7 +295,7 @@ async def create(
295295
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
296296
dimension_names: Iterable[str] | None = None,
297297
# runtime
298-
exists_ok: bool = False,
298+
overwrite: bool = False,
299299
data: npt.ArrayLike | None = None,
300300
) -> AsyncArray[ArrayV3Metadata]: ...
301301

@@ -323,7 +323,7 @@ async def create(
323323
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
324324
dimension_names: Iterable[str] | None = None,
325325
# runtime
326-
exists_ok: bool = False,
326+
overwrite: bool = False,
327327
data: npt.ArrayLike | None = None,
328328
) -> AsyncArray[ArrayV3Metadata]: ...
329329

@@ -356,7 +356,7 @@ async def create(
356356
filters: list[dict[str, JSON]] | None = None,
357357
compressor: dict[str, JSON] | None = None,
358358
# runtime
359-
exists_ok: bool = False,
359+
overwrite: bool = False,
360360
data: npt.ArrayLike | None = None,
361361
) -> AsyncArray[ArrayV3Metadata] | AsyncArray[ArrayV2Metadata]: ...
362362

@@ -388,7 +388,7 @@ async def create(
388388
filters: list[dict[str, JSON]] | None = None,
389389
compressor: dict[str, JSON] | None = None,
390390
# runtime
391-
exists_ok: bool = False,
391+
overwrite: bool = False,
392392
data: npt.ArrayLike | None = None,
393393
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
394394
"""
@@ -430,7 +430,7 @@ async def create(
430430
compressor : dict[str, JSON], optional
431431
The compressor used to compress the data (default is None).
432432
V2 only. V3 arrays should not have 'compressor' parameter.
433-
exists_ok : bool, optional
433+
overwrite : bool, optional
434434
Whether to raise an error if the store already exists (default is False).
435435
data : npt.ArrayLike, optional
436436
The data to be inserted into the array (default is None).
@@ -490,7 +490,7 @@ async def create(
490490
codecs=codecs,
491491
dimension_names=dimension_names,
492492
attributes=attributes,
493-
exists_ok=exists_ok,
493+
overwrite=overwrite,
494494
order=order,
495495
)
496496
elif zarr_format == 2:
@@ -515,7 +515,7 @@ async def create(
515515
filters=filters,
516516
compressor=compressor,
517517
attributes=attributes,
518-
exists_ok=exists_ok,
518+
overwrite=overwrite,
519519
)
520520
else:
521521
raise ValueError(f"Insupported zarr_format. Got: {zarr_format}")
@@ -545,9 +545,9 @@ async def _create_v3(
545545
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
546546
dimension_names: Iterable[str] | None = None,
547547
attributes: dict[str, JSON] | None = None,
548-
exists_ok: bool = False,
548+
overwrite: bool = False,
549549
) -> AsyncArray[ArrayV3Metadata]:
550-
if exists_ok:
550+
if overwrite:
551551
if store_path.store.supports_deletes:
552552
await store_path.delete_dir()
553553
else:
@@ -597,14 +597,14 @@ async def _create_v2(
597597
dtype: npt.DTypeLike,
598598
chunks: ChunkCoords,
599599
dimension_separator: Literal[".", "/"] | None = None,
600-
fill_value: None | float = None,
600+
fill_value: float | None = None,
601601
order: MemoryOrder | None = None,
602602
filters: list[dict[str, JSON]] | None = None,
603603
compressor: dict[str, JSON] | None = None,
604604
attributes: dict[str, JSON] | None = None,
605-
exists_ok: bool = False,
605+
overwrite: bool = False,
606606
) -> AsyncArray[ArrayV2Metadata]:
607-
if exists_ok:
607+
if overwrite:
608608
if store_path.store.supports_deletes:
609609
await store_path.delete_dir()
610610
else:
@@ -1464,7 +1464,7 @@ def create(
14641464
filters: list[dict[str, JSON]] | None = None,
14651465
compressor: dict[str, JSON] | None = None,
14661466
# runtime
1467-
exists_ok: bool = False,
1467+
overwrite: bool = False,
14681468
) -> Array:
14691469
"""Creates a new Array instance from an initialized store.
14701470
@@ -1494,7 +1494,7 @@ def create(
14941494
The filters used to compress the data (default is None).
14951495
compressor : dict[str, JSON], optional
14961496
The compressor used to compress the data (default is None).
1497-
exists_ok : bool, optional
1497+
overwrite : bool, optional
14981498
Whether to raise an error if the store already exists (default is False).
14991499
15001500
Returns
@@ -1519,7 +1519,7 @@ def create(
15191519
order=order,
15201520
filters=filters,
15211521
compressor=compressor,
1522-
exists_ok=exists_ok,
1522+
overwrite=overwrite,
15231523
),
15241524
)
15251525
return cls(async_array)

src/zarr/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
ChunkCoordsLike = Iterable[int]
3737
ZarrFormat = Literal[2, 3]
3838
NodeType = Literal["array", "group"]
39-
JSON = None | str | int | float | Mapping[str, "JSON"] | tuple["JSON", ...]
39+
JSON = str | int | float | Mapping[str, "JSON"] | tuple["JSON", ...] | None
4040
MemoryOrder = Literal["C", "F"]
4141
AccessModeLiteral = Literal["r", "r+", "a", "w", "w-"]
4242

0 commit comments

Comments
 (0)