8000 Strengthen pickling test and fix ZipStore __getstate__() by maxrjones · Pull Request #2807 · zarr-developers/zarr-python · GitHub
[go: up one dir, main page]

Skip to content

Strengthen pickling test and fix ZipStore __getstate__() #2807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/2807.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix pickling for ZipStore
3 changes: 2 additions & 1 deletion src/zarr/storage/_zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ async def _open(self) -> None:
self._sync_open()

def __getstate__(self) -> dict[str, Any]:
state = self.__dict__
# We need a copy to not modify the state of the original store
state = self.__dict__.copy()
for attr in ["_zf", "_lock"]:
state.pop(attr, None)
return state
Expand Down
8 changes: 7 additions & 1 deletion src/zarr/testing/store.py
6711
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,16 @@ def test_store_eq(self, store: S, store_kwargs: dict[str, Any]) -> None:
store2 = self.store_cls(**store_kwargs)
assert store == store2

def test_serializable_store(self, store: S) -> None:
async def test_serializable_store(self, store: S) -> None:
new_store: S = pickle.loads(pickle.dumps(store))
assert new_store == store
assert new_store.read_only == store.read_only
# quickly roundtrip data to a key to test that new store works
data_buf = self.buffer_cls.from_bytes(b"\x01\x02\x03\x04")
key = "foo"
await store.set(key, data_buf)
observed = await store.get(key, prototype=default_buffer_prototype())
assert_bytes_equal(observed, data_buf)

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