Skip to content

Commit 12dfaf4

Browse files
committed
deprecate zarr.storage.default_compressor
1 parent 876e67d commit 12dfaf4

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

src/zarr/core/config.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ def reset(self) -> None:
3131
# The config module is responsible for managing the configuration of zarr and is based on the Donfig python library.
3232
# For selecting custom implementations of codecs, pipelines, buffers and ndbuffers, first register the implementations
3333
# in the registry and then select them in the config.
34-
# e.g. an implementation of the bytes codec in a class "NewBytesCodec", requires the value of codecs.bytes.name to be
35-
# "NewBytesCodec".
34+
# e.g. an implementation of the bytes codec in a class "your.module.NewBytesCodec", requires the value of codecs.bytes
35+
# to be "your.module.NewBytesCodec".
3636
# Donfig can be configured programmatically, by environment variables, or from YAML files in standard locations
37-
# e.g. export ZARR_CODECS__BYTES__NAME="NewBytesCodec"
37+
# e.g. export ZARR_CODECS__BYTES="your.module.NewBytesCodec"
3838
# (for more information see github.com/pytroll/donfig)
3939
# Default values below point to the standard implementations of zarr-python
4040
config = Config(
@@ -71,7 +71,6 @@ def reset(self) -> None:
7171
},
7272
"buffer": "zarr.core.buffer.cpu.Buffer",
7373
"ndbuffer": "zarr.core.buffer.cpu.NDBuffer",
74-
7574
}
7675
],
7776
)

src/zarr/storage/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import sys
2+
import warnings
3+
from types import ModuleType
4+
from typing import Any
5+
16
from zarr.storage.common import StoreLike, StorePath, make_store_path
27
from zarr.storage.local import LocalStore
38
from zarr.storage.logging import LoggingStore
@@ -17,3 +22,20 @@
1722
"ZipStore",
1823
"make_store_path",
1924
]
25+
26+
27+
class VerboseModule(ModuleType):
28+
def __setattr__(self, attr: str, value: Any) -> None:
29+
if attr == "default_compressor":
30+
warnings.warn(
31+
"setting zarr.storage.default_compressor is deprecated, use "
32+
"zarr.config to configure array.v2_default_compressor "
33+
"e.g. config.set({'codecs.zstd':'your.module.Zstd', 'array.v2_default_compressor.numeric': 'zstd'})",
34+
DeprecationWarning,
35+
stacklevel=1,
36+
)
37+
else:
38+
super().__setattr__(attr, value)
39+
40+
41+
sys.modules[__name__].__class__ = VerboseModule

tests/test_v2.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ def test_codec_pipeline() -> None:
8282

8383
@pytest.mark.parametrize("dtype", ["|S", "|V"])
8484
async def test_v2_encode_decode(dtype):
85-
with config.set(
86-
{
87-
"array.v2_default_compressor.bytes": "vlen-bytes",
88-
}
89-
):
85+
with config.set({"array.v2_default_compressor.bytes": "vlen-bytes"}):
9086
store = zarr.storage.MemoryStore()
9187
g = zarr.group(store=store, zarr_format=2)
9288
g.create_array(
@@ -206,6 +202,11 @@ def test_v2_non_contiguous(array_order: Literal["C", "F"], data_order: Literal["
206202
np.testing.assert_array_equal(arr[slice(6, 9, None), slice(3, 6, None)], a)
207203

208204

205+
def test_default_compressor_deprecation_warning():
206+
with pytest.warns(DeprecationWarning):
207+
zarr.storage.default_compressor = "zarr.codecs.zstd.ZstdCodec()"
208+
209+
209210
@pytest.mark.parametrize(
210211
"dtype_expected",
211212
[["b", "zstd"], ["i", "zstd"], ["f", "zstd"], ["|S1", "vlen-bytes"], ["|U1", "vlen-utf8"]],

0 commit comments

Comments
 (0)