Skip to content

Deprecate zarr.storage #2196

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

Closed
Closed
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
40 changes: 40 additions & 0 deletions src/zarr/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import importlib
import warnings
from typing import Any

_names = [
"DictStore",
"KVStore",
"DirectoryStore",
"ZipStore",
"FSStore",
]
_mappings = {
"DictStore": ("memory", "MemoryStore"),
"KVStore": ("memory", "MemoryStore"),
"DirectoryStore": ("local", "LocalStore"),
"ZipStore": ("zip", "ZipStore"),
"FSStore": ("remote", "RemoteStore"),
}


def _deprecated_import(old: str) -> Any:
try:
submodule, new = _mappings[old]
mod = importlib.import_module(f"zarr.store.{submodule}")
store = getattr(mod, new)
except KeyError as e:
raise ImportError(f"cannot import name {old}") from e
else:
warnings.warn(
"'zarr.storage' is deprecated. Import from 'zarr.store' instead.",
FutureWarning,
stacklevel=3,
)
return store


def __getattr__(name: str) -> Any:
if name in _names:
return _deprecated_import(name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
25 changes: 25 additions & 0 deletions tests/v3/test_storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import importlib

import pytest

import zarr.store.local
import zarr.store.memory
import zarr.store.remote
import zarr.store.zip


@pytest.mark.parametrize(
["name", "expected"],
[
("DictStore", zarr.store.memory.MemoryStore),
("KVStore", zarr.store.memory.MemoryStore),
("DirectoryStore", zarr.store.local.LocalStore),
("FSStore", zarr.store.remote.RemoteStore),
("ZipStore", zarr.store.zip.ZipStore),
],
)
def test_storage_deprecated(name: str, expected: type) -> None:
with pytest.warns(FutureWarning, match="zarr.store"):
result = getattr(importlib.import_module("zarr.storage"), name)

assert result == expected