Skip to content

Commit

Permalink
Merge branch 'main' into testing-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b authored Jan 25, 2025
2 parents 128ef99 + 9fd4545 commit 1faa66c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changes/2762.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed ZipStore to make sure the correct attributes are saved when instances are pickled.
This fixes a previous bug that prevent using ZipStore with a ProcessPoolExecutor.
13 changes: 8 additions & 5 deletions src/zarr/storage/_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ def _sync_open(self) -> None:
async def _open(self) -> None:
self._sync_open()

def __getstate__(self) -> tuple[Path, ZipStoreAccessModeLiteral, int, bool]:
return self.path, self._zmode, self.compression, self.allowZip64

def __setstate__(self, state: Any) -> None:
self.path, self._zmode, self.compression, self.allowZip64 = state
def __getstate__(self) -> dict[str, Any]:
state = self.__dict__
for attr in ["_zf", "_lock"]:
state.pop(attr, None)
return state

def __setstate__(self, state: dict[str, Any]) -> None:
self.__dict__ = state
self._is_open = False
self._sync_open()

Expand Down
5 changes: 3 additions & 2 deletions src/zarr/testing/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ def test_store_eq(self, store: S, store_kwargs: dict[str, Any]) -> None:
assert store == store2

def test_serializable_store(self, store: S) -> None:
foo = pickle.dumps(store)
assert pickle.loads(foo) == store
new_store: S = pickle.loads(pickle.dumps(store))
assert new_store == store
assert new_store.read_only == store.read_only

def test_store_read_only(self, store: S) -> None:
assert not store.read_only
Expand Down

0 comments on commit 1faa66c

Please sign in to comment.