Skip to content

Commit

Permalink
Fix pickling of ZipStore
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Jan 24, 2025
1 parent ad99a67 commit 62826df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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 @@ -76,8 +76,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 62826df

Please sign in to comment.