Skip to content

Commit 0ae0fda

Browse files
committed
move for ZipStore
1 parent e6d7c8d commit 0ae0fda

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/zarr/storage/_zip.py

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

33
import os
4+
import shutil
45
import threading
56
import time
67
import zipfile
@@ -288,3 +289,16 @@ async def list_dir(self, prefix: str) -> AsyncIterator[str]:
288289
if k not in seen:
289290
seen.add(k)
290291
yield k
292+
293+
async def move(self, path: Path | str) -> None:
294+
# docstring inherited
295+
296+
if isinstance(path, str):
297+
path = Path(path)
298+
if not isinstance(path, Path):
299+
raise TypeError(
300+
f"'path' must be a string or Path instance. Got an instance of {type(path)} instead."
301+
)
302+
os.makedirs(path, exist_ok=True)
303+
shutil.move(self.path, path)
304+
self.path = path

tests/test_store/test_zip.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
import zarr
13+
from zarr import create_array
1314
from zarr.core.buffer import Buffer, cpu, default_buffer_prototype
1415
from zarr.storage import ZipStore
1516
from zarr.testing.store import StoreTests
@@ -135,3 +136,17 @@ def test_externally_zipped_store(self, tmp_path: Path) -> None:
135136
zipped = zarr.open_group(ZipStore(zip_path, mode="r"), mode="r")
136137
assert list(zipped.keys()) == list(root.keys())
137138
assert list(zipped["foo"].keys()) == list(root["foo"].keys())
139+
140+
async def test_move(self, tmp_path: Path):
141+
origin = tmp_path / "origin"
142+
destination = tmp_path / "destintion"
143+
144+
store = await ZipStore.open(path=origin, mode="w")
145+
array = create_array(store, data=np.arange(10))
146+
147+
await store.move(destination)
148+
149+
assert store.path == destination
150+
assert destination.exists()
151+
assert not origin.exists()
152+
assert np.array_equal(array[...], np.arange(10))

0 commit comments

Comments
 (0)