Skip to content

Commit 01b73a7

Browse files
authored
rename exists_ok to overwrite (#2548)
1 parent 4e53a70 commit 01b73a7

File tree

7 files changed

+83
-83
lines changed

7 files changed

+83
-83
lines changed

src/zarr/api/asynchronous.py

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

7373

74-
def _infer_exists_ok(mode: AccessModeLiteral) -> bool:
74+
def _infer_overwrite(mode: AccessModeLiteral) -> bool:
7575
"""
7676
Check that an ``AccessModeLiteral`` is compatible with overwriting an existing Zarr node.
7777
"""
@@ -414,14 +414,14 @@ async def save_array(
414414
arr = np.array(arr)
415415
shape = arr.shape
416416
chunks = getattr(arr, "chunks", None) # for array-likes with chunks attribute
417-
exists_ok = kwargs.pop("exists_ok", None) or _infer_exists_ok(mode)
417+
overwrite = kwargs.pop("overwrite", None) or _infer_overwrite(mode)
418418
new = await AsyncArray.create(
419419
store_path,
420420
zarr_format=zarr_format,
421421
shape=shape,
422422
dtype=arr.dtype,
423423
chunks=chunks,
424-
exists_ok=exists_ok,
424+
overwrite=overwrite,
425425
**kwargs,
426426
)
427427
await new.setitem(slice(None), arr)
@@ -647,7 +647,7 @@ async def group(
647647
return await AsyncGroup.from_store(
648648
store=store_path,
649649
zarr_format=_zarr_format,
650-
exists_ok=overwrite,
650+
overwrite=overwrite,
651651
attributes=attributes,
652652
)
653653

@@ -753,12 +753,12 @@ async def open_group(
753753
except (KeyError, FileNotFoundError):
754754
pass
755755
if mode in _CREATE_MODES:
756-
exists_ok = _infer_exists_ok(mode)
756+
overwrite = _infer_overwrite(mode)
757757
_zarr_format = zarr_format or _default_zarr_version()
758758
return await AsyncGroup.from_store(
759759
store_path,
760760
zarr_format=_zarr_format,
761-
exists_ok=exists_ok,
761+
overwrite=overwrite,
762762
attributes=attributes,
763763
)
764764
raise FileNotFoundError(f"Unable to find group: {store_path}")
@@ -933,7 +933,7 @@ async def create(
933933
dtype=dtype,
934934
compressor=compressor,
935935
fill_value=fill_value,
936-
exists_ok=overwrite,
936+
overwrite=overwrite,
937937
filters=filters,
938938
dimension_separator=dimension_separator,
939939
zarr_format=zarr_format,
@@ -1120,12 +1120,12 @@ async def open_array(
11201120
return await AsyncArray.open(store_path, zarr_format=zarr_format)
11211121
except FileNotFoundError:
11221122
if not store_path.read_only and mode in _CREATE_MODES:
1123-
exists_ok = _infer_exists_ok(mode)
1123+
overwrite = _infer_overwrite(mode)
11241124
_zarr_format = zarr_format or _default_zarr_version()
11251125
return await create(
11261126
store=store_path,
11271127
zarr_format=_zarr_format,
1128-
overwrite=exists_ok,
1128+
overwrite=overwrite,
11291129
**kwargs,
11301130
)
11311131
raise

src/zarr/core/array.py

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

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

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

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

@@ -387,7 +387,7 @@ async def create(
387387
filters: list[dict[str, JSON]] | None = None,
388388
compressor: dict[str, JSON] | None = None,
389389
# runtime
390-
exists_ok: bool = False,
390+
overwrite: bool = False,
391391
data: npt.ArrayLike | None = None,
392392
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
393393
"""
@@ -429,7 +429,7 @@ async def create(
429429
compressor : dict[str, JSON], optional
430430
The compressor used to compress the data (default is None).
431431
V2 only. V3 arrays should not have 'compressor' parameter.
432-
exists_ok : bool, optional
432+
overwrite : bool, optional
433433
Whether to raise an error if the store already exists (default is False).
434434
data : npt.ArrayLike, optional
435435
The data to be inserted into the array (default is None).
@@ -489,7 +489,7 @@ async def create(
489489
codecs=codecs,
490490
dimension_names=dimension_names,
491491
attributes=attributes,
492-
exists_ok=exists_ok,
492+
overwrite=overwrite,
493493
order=order,
494494
)
495495
elif zarr_format == 2:
@@ -522,7 +522,7 @@ async def create(
522522
filters=filters,
523523
compressor=compressor,
524524
attributes=attributes,
525-
exists_ok=exists_ok,
525+
overwrite=overwrite,
526526
)
527527
else:
528528
raise ValueError(f"Insupported zarr_format. Got: {zarr_format}")
@@ -552,9 +552,9 @@ async def _create_v3(
552552
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
553553
dimension_names: Iterable[str] | None = None,
554554
attributes: dict[str, JSON] | None = None,
555-
exists_ok: bool = False,
555+
overwrite: bool = False,
556556
) -> AsyncArray[ArrayV3Metadata]:
557-
if exists_ok:
557+
if overwrite:
558558
if store_path.store.supports_deletes:
559559
await store_path.delete_dir()
560560
else:
@@ -609,9 +609,9 @@ async def _create_v2(
609609
filters: list[dict[str, JSON]] | None = None,
610610
compressor: dict[str, JSON] | None = None,
611611
attributes: dict[str, JSON] | None = None,
612-
exists_ok: bool = False,
612+
overwrite: bool = False,
613613
) -> AsyncArray[ArrayV2Metadata]:
614-
if exists_ok:
614+
if overwrite:
615615
if store_path.store.supports_deletes:
616616
await store_path.delete_dir()
617617
else:
@@ -1463,7 +1463,7 @@ def create(
14631463
filters: list[dict[str, JSON]] | None = None,
14641464
compressor: dict[str, JSON] | None = None,
14651465
# runtime
1466-
exists_ok: bool = False,
1466+
overwrite: bool = False,
14671467
) -> Array:
14681468
"""Creates a new Array instance from an initialized store.
14691469
@@ -1493,7 +1493,7 @@ def create(
14931493
The filters used to compress the data (default is None).
14941494
compressor : dict[str, JSON], optional
14951495
The compressor used to compress the data (default is None).
1496-
exists_ok : bool, optional
1496+
overwrite : bool, optional
14971497
Whether to raise an error if the store already exists (default is False).
14981498
14991499
Returns
@@ -1518,7 +1518,7 @@ def create(
15181518
order=order,
15191519
filters=filters,
15201520
compressor=compressor,
1521-
exists_ok=exists_ok,
1521+
overwrite=overwrite,
15221522
),
15231523
)
15241524
return cls(async_array)

src/zarr/core/group.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ async def from_store(
410410
store: StoreLike,
411411
*,
412412
attributes: dict[str, Any] | None = None,
413-
exists_ok: bool = False,
413+
overwrite: bool = False,
414414
zarr_format: ZarrFormat = 3,
415415
) -> AsyncGroup:
416416
store_path = await make_store_path(store)
417417

418-
if exists_ok:
418+
if overwrite:
419419
if store_path.store.supports_deletes:
420420
await store_path.delete_dir()
421421
else:
@@ -629,7 +629,7 @@ async def setitem(self, key: str, value: Any) -> None:
629629
"""
630630
path = self.store_path / key
631631
await async_api.save_array(
632-
store=path, arr=value, zarr_format=self.metadata.zarr_format, exists_ok=True
632+
store=path, arr=value, zarr_format=self.metadata.zarr_format, overwrite=True
633633
)
634634

635635
async def getitem(
@@ -919,7 +919,7 @@ async def create_group(
919919
self,
920920
name: str,
921921
*,
922-
exists_ok: bool = False,
922+
overwrite: bool = False,
923923
attributes: dict[str, Any] | None = None,
924924
) -> AsyncGroup:
925925
"""Create a sub-group.
@@ -928,7 +928,7 @@ async def create_group(
928928
----------
929929
name : str
930930
Group name.
931-
exists_ok : bool, optional
931+
overwrite : bool, optional
932932
If True, do not raise an error if the group already exists.
933933
attributes : dict, optional
934934
Group attributes.
@@ -941,7 +941,7 @@ async def create_group(
941941
return await type(self).from_store(
942942
self.store_path / name,
943943
attributes=attributes,
944-
exists_ok=exists_ok,
944+
overwrite=overwrite,
945945
zarr_format=self.metadata.zarr_format,
946946
)
947947

@@ -960,8 +960,8 @@ async def require_group(self, name: str, overwrite: bool = False) -> AsyncGroup:
960960
g : AsyncGroup
961961
"""
962962
if overwrite:
963-
# TODO: check that exists_ok=True errors if an array exists where the group is being created
964-
grp = await self.create_group(name, exists_ok=True)
963+
# TODO: check that overwrite=True errors if an array exists where the group is being created
964+
grp = await self.create_group(name, overwrite=True)
965965
else:
966966
try:
967967
item: (
@@ -1018,7 +1018,7 @@ async def create_array(
10181018
filters: list[dict[str, JSON]] | None = None,
10191019
compressor: dict[str, JSON] | None = None,
10201020
# runtime
1021-
exists_ok: bool = False,
1021+
overwrite: bool = False,
10221022
data: npt.ArrayLike | None = None,
10231023
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata]:
10241024
"""
@@ -1052,7 +1052,7 @@ async def create_array(
10521052
Filters for the array.
10531053
compressor : dict[str, JSON] | None = None
10541054
The compressor for the array.
1055-
exists_ok : bool = False
1055+
overwrite : bool = False
10561056
If True, a pre-existing array or group at the path of this array will
10571057
be overwritten. If False, the presence of a pre-existing array or group is
10581058
an error.
@@ -1077,7 +1077,7 @@ async def create_array(
10771077
order=order,
10781078
filters=filters,
10791079
compressor=compressor,
1080-
exists_ok=exists_ok,
1080+
overwrite=overwrite,
10811081
zarr_format=self.metadata.zarr_format,
10821082
data=data,
10831083
)
@@ -1651,7 +1651,7 @@ def from_store(
16511651
*,
16521652
attributes: dict[str, Any] | None = None,
16531653
zarr_format: ZarrFormat = 3,
1654-
exists_ok: bool = False,
1654+
overwrite: bool = False,
16551655
) -> Group:
16561656
"""Instantiate a group from an initialized store.
16571657
@@ -1663,7 +1663,7 @@ def from_store(
16631663
A dictionary of JSON-serializable values with user-defined attributes.
16641664
zarr_format : {2, 3}, optional
16651665
Zarr storage format version.
1666-
exists_ok : bool, optional
1666+
overwrite : bool, optional
16671667
If True, do not raise an error if the group already exists.
16681668
16691669
Returns
@@ -1680,7 +1680,7 @@ def from_store(
16801680
AsyncGroup.from_store(
16811681
store,
16821682
attributes=attributes,
1683-
exists_ok=exists_ok,
1683+
overwrite=overwrite,
16841684
zarr_format=zarr_format,
16851685
),
16861686
)
@@ -2217,7 +2217,7 @@ def create_array(
22172217
filters: list[dict[str, JSON]] | None = None,
22182218
compressor: dict[str, JSON] | None = None,
22192219
# runtime
2220-
exists_ok: bool = False,
2220+
overwrite: bool = False,
22212221
data: npt.ArrayLike | None = None,
22222222
) -> Array:
22232223
"""Create a zarr array within this AsyncGroup.
@@ -2251,7 +2251,7 @@ def create_array(
22512251
Filters for the array.
22522252
compressor : dict[str, JSON] | None = None
22532253
The compressor for the array.
2254-
exists_ok : bool = False
2254+
overwrite : bool = False
22552255
If True, a pre-existing array or group at the path of this array will
22562256
be overwritten. If False, the presence of a pre-existing array or group is
22572257
an error.
@@ -2280,7 +2280,7 @@ def create_array(
22802280
order=order,
22812281
filters=filters,
22822282
compressor=compressor,
2283-
exists_ok=exists_ok,
2283+
overwrite=overwrite,
22842284
data=data,
22852285
)
22862286
)
@@ -2558,7 +2558,7 @@ def array(
25582558
filters: list[dict[str, JSON]] | None = None,
25592559
compressor: dict[str, JSON] | None = None,
25602560
# runtime
2561-
exists_ok: bool = False,
2561+
overwrite: bool = False,
25622562
data: npt.ArrayLike | None = None,
25632563
) -> Array:
25642564
"""Create a zarr array within this AsyncGroup.
@@ -2592,7 +2592,7 @@ def array(
25922592
Filters for the array.
25932593
compressor : dict[str, JSON] | None = None
25942594
The compressor for the array.
2595-
exists_ok : bool = False
2595+
overwrite : bool = False
25962596
If True, a pre-existing array or group at the path of this array will
25972597
be overwritten. If False, the presence of a pre-existing array or group is
25982598
an error.
@@ -2622,7 +2622,7 @@ def array(
26222622
order=order,
26232623
filters=filters,
26242624
compressor=compressor,
2625-
exists_ok=exists_ok,
2625+
overwrite=overwrite,
26262626
data=data,
26272627
)
26282628
)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def async_group(request: pytest.FixtureRequest, tmpdir: LEGACY_PATH) -> As
100100
store,
101101
attributes=param.attributes,
102102
zarr_format=param.zarr_format,
103-
exists_ok=False,
103+
overwrite=False,
104104
)
105105

106106

0 commit comments

Comments
 (0)