Skip to content
Open
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
8 changes: 8 additions & 0 deletions changes/4029.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
`zarr.storage` is no longer replaced by a `ModuleType` subclass at import time.
The subclass only existed to warn about the long-deprecated
`zarr.storage.default_compressor` attribute, but serializers that dispatch on
the exact type of an object (such as `cloudpickle`, which Dask uses by default)
could not serialize the module and raised
`TypeError: cannot pickle 'VerboseModule' object`. Setting
`zarr.storage.default_compressor` no longer emits a deprecation warning; use
`zarr.config` to configure `array.v2_default_compressor` instead.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ homepage = "https://github.com/zarr-developers/zarr-python"
# pins deliberately, e.g. via dependabot or `uv lock --upgrade`.
[dependency-groups]
test = [
"cloudpickle==3.1.2",
"coverage==7.16.2",
"pytest==9.1.1",
"pytest-asyncio==1.4.0",
Expand Down
23 changes: 0 additions & 23 deletions src/zarr/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import sys
import warnings
from types import ModuleType
from typing import Any

from zarr.errors import ZarrDeprecationWarning
from zarr.storage._common import StoreLike, StorePath
from zarr.storage._fsspec import FsspecStore
from zarr.storage._local import LocalStore
Expand All @@ -26,20 +20,3 @@
"WrapperStore",
"ZipStore",
]


class VerboseModule(ModuleType):
def __setattr__(self, attr: str, value: Any) -> None:
if attr == "default_compressor":
warnings.warn(
"setting zarr.storage.default_compressor is deprecated, use "
"zarr.config to configure array.v2_default_compressor "
"e.g. config.set({'codecs.zstd':'numcodecs.Zstd', 'array.v2_default_compressor.numeric': 'zstd'})",
ZarrDeprecationWarning,
stacklevel=1,
)
else:
super().__setattr__(attr, value)


sys.modules[__name__].__class__ = VerboseModule
14 changes: 14 additions & 0 deletions tests/test_store/test_core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import tempfile
from collections.abc import Awaitable, Callable, Generator
from pathlib import Path
from types import ModuleType
from typing import Any, Literal

import cloudpickle
import pytest
from packaging.version import parse as parse_version

Expand Down Expand Up @@ -434,3 +436,15 @@ def test_different_open_mode(tmp_path: Path) -> None:
match="Store is not read-only but mode is 'r'. Unable to create a read-only copy of the store. Please use a read-only store or a storage class that implements .with_read_only().",
):
zarr.open_array(store=zip_store, path="a", zarr_format=2, mode="r")


def test_storage_module_is_picklable() -> None:
# `zarr.storage` used to be swapped for a `VerboseModule` subclass of
# `types.ModuleType` in order to warn about the long-deprecated
# `zarr.storage.default_compressor` attribute. cloudpickle dispatches on the
# exact type of an object, so the subclass was not registered and
# serializing the module raised `TypeError: cannot pickle 'VerboseModule'
# object`, which broke passing `zarr.storage.ObjectStore` around with Dask.
# See issue #4029.
assert type(zarr.storage) is ModuleType
assert cloudpickle.loads(cloudpickle.dumps(zarr.storage)) is zarr.storage
6 changes: 0 additions & 6 deletions tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from zarr.core.dtype.wrapper import ZDType
from zarr.core.group import Group
from zarr.core.sync import sync
from zarr.errors import ZarrDeprecationWarning
from zarr.storage import MemoryStore, StorePath


Expand Down Expand Up @@ -225,11 +224,6 @@ def test_v2_non_contiguous(numpy_order: Literal["C", "F"], zarr_order: Literal["
assert (sub_arr).flags.c_contiguous


def test_default_compressor_deprecation_warning() -> None:
with pytest.warns(ZarrDeprecationWarning, match="default_compressor is deprecated"):
zarr.storage.default_compressor = "zarr.codecs.zstd.ZstdCodec()" # type: ignore[attr-defined]


@pytest.mark.parametrize("fill_value", [None, (b"", 0, 0.0)], ids=["no_fill", "fill"])
def test_structured_dtype_roundtrip(fill_value: float | bytes, tmp_path: Path) -> None:
a = np.array(
Expand Down
17 changes: 16 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading