Skip to content
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

document storage classes and some developer apis #2279

Merged
merged 37 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fe49f5f
fix: zarr v2 compatability fixes
jhamman Sep 14, 2024
9a1580b
move zarr.store to zarr.storage
jhamman Sep 16, 2024
0d89912
make chunks a tuple
jhamman Sep 17, 2024
d78e384
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Sep 17, 2024
e534279
Apply suggestions from code review
jhamman Sep 17, 2024
dea4a3d
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Sep 18, 2024
7800f38
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Sep 22, 2024
93b61fc
more merge conflict resolution
jhamman Sep 23, 2024
88afe52
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Sep 29, 2024
fb6752d
fixups
jhamman Sep 29, 2024
0b1dedc
fixup zipstore
jhamman Sep 29, 2024
322918a
Apply suggestions from code review
jhamman Sep 29, 2024
a95d54a
Apply suggestions from code review
jhamman Sep 30, 2024
128eb53
add test
jhamman Sep 30, 2024
3c170ef
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Sep 30, 2024
54ab9ef
extend test
jhamman Sep 30, 2024
77f2938
clean up parents
jhamman Sep 30, 2024
2295d76
debug race condition
jhamman Sep 30, 2024
5879d67
more debug
jhamman Sep 30, 2024
f54f6f2
document storage classes and some developer apis
jhamman Oct 1, 2024
3940d22
Update src/zarr/core/array.py
jhamman Oct 1, 2024
c9d1c50
Merge branch 'fix/dask-compat' into doc/storage
jhamman Oct 2, 2024
83fa3ac
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Oct 7, 2024
f2137fb
Merge branch 'doc/storage' of github.com:jhamman/zarr-python into doc…
jhamman Oct 7, 2024
f44601b
Merge branch 'v3' into doc/storage
jhamman Oct 9, 2024
731c22a
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Oct 10, 2024
4e93aa0
inherit docstrings from baseclass
jhamman Oct 10, 2024
dad94e2
Merge branch 'doc/storage' of github.com:jhamman/zarr-python into doc…
jhamman Oct 10, 2024
5477d32
fix sphinx warning
jhamman Oct 11, 2024
728d4f7
# docstring inherited
jhamman Oct 11, 2024
e293b47
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Oct 11, 2024
cee730c
Merge branch 'v3' of https://github.com/zarr-developers/zarr-python i…
jhamman Oct 11, 2024
3f7290f
add storage guide
jhamman Oct 11, 2024
35a6428
add missing file
jhamman Oct 11, 2024
a78461e
update links
jhamman Oct 11, 2024
eff01ce
Merge branch 'v3' into doc/storage
jhamman Oct 11, 2024
c1f0923
Merge branch 'v3' into doc/storage
dstansby Oct 12, 2024
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
30 changes: 30 additions & 0 deletions src/zarr/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,33 @@ def parse_order(data: Any) -> Literal["C", "F"]:
if data in ("C", "F"):
return cast(Literal["C", "F"], data)
raise ValueError(f"Expected one of ('C', 'F'), got {data} instead.")


def _inherit_docstrings(cls: type[Any]) -> type[Any]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstrings are already automatically inherited, e.g. see Store and LocalStore. So I think this isn't needed and can be gotten rid of.

"""
Inherit docstrings from base class

Iterate over the methods of the class and if a method is missing a docstring,
try to inherit one from a base class (ABC).

Parameters
----------
cls : object
the class to inherit docstrings from

Returns
-------
cls
the class with updated docstrings
"""
# Iterate over the methods of the class
for name, method in cls.__dict__.items():
# Skip if it's not a callable (method or function)
if callable(method):
# Get the corresponding method from the base class (ABC)
for base in cls.__bases__:
base_method = getattr(base, name, None)
if base_method and not method.__doc__:
method.__doc__ = base_method.__doc__
break
return cls
2 changes: 2 additions & 0 deletions src/zarr/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from zarr.storage.common import StoreLike, StorePath, make_store_path
from zarr.storage.local import LocalStore
from zarr.storage.logging import LoggingStore
from zarr.storage.memory import MemoryStore
from zarr.storage.remote import RemoteStore
from zarr.storage.zip import ZipStore

__all__ = [
"LocalStore",
"LoggingStore",
"MemoryStore",
"RemoteStore",
"StoreLike",
Expand Down
3 changes: 2 additions & 1 deletion src/zarr/storage/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from zarr.abc.store import ByteRangeRequest, Store
from zarr.core.buffer import Buffer
from zarr.core.common import concurrent_map
from zarr.core.common import _inherit_docstrings, concurrent_map

if TYPE_CHECKING:
from collections.abc import AsyncGenerator, Iterable
Expand Down Expand Up @@ -66,6 +66,7 @@ def _put(
return f.write(view)


@_inherit_docstrings
class LocalStore(Store):
"""
Local file system store.
Expand Down
2 changes: 2 additions & 0 deletions src/zarr/storage/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from zarr.abc.store import AccessMode, ByteRangeRequest, Store
from zarr.core.buffer import Buffer
from zarr.core.common import _inherit_docstrings

if TYPE_CHECKING:
from collections.abc import AsyncGenerator, Generator, Iterable
Expand All @@ -17,6 +18,7 @@
from zarr.core.common import AccessModeLiteral


@_inherit_docstrings
class LoggingStore(Store):
"""
Store wrapper that logs all calls to the wrapped store.
Expand Down
3 changes: 2 additions & 1 deletion src/zarr/storage/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from zarr.abc.store import ByteRangeRequest, Store
from zarr.core.buffer import Buffer, gpu
from zarr.core.common import concurrent_map
from zarr.core.common import _inherit_docstrings, concurrent_map
from zarr.storage._utils import _normalize_interval_index

if TYPE_CHECKING:
Expand All @@ -14,6 +14,7 @@
from zarr.core.common import AccessModeLiteral


@_inherit_docstrings
class MemoryStore(Store):
"""
In-memory store for testing purposes.
Expand Down
2 changes: 2 additions & 0 deletions src/zarr/storage/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from zarr.abc.store import ByteRangeRequest, Store
from zarr.core.buffer import Buffer
from zarr.core.common import _inherit_docstrings
from zarr.storage.common import _dereference_path

if TYPE_CHECKING:
Expand All @@ -24,6 +25,7 @@
)


@_inherit_docstrings
class RemoteStore(Store):
"""
A remote Store based on FSSpec
Expand Down
2 changes: 2 additions & 0 deletions src/zarr/storage/zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@

from zarr.abc.store import ByteRangeRequest, Store
from zarr.core.buffer import Buffer, BufferPrototype
from zarr.core.common import _inherit_docstrings

if TYPE_CHECKING:
from collections.abc import AsyncGenerator, Iterable

ZipStoreAccessModeLiteral = Literal["r", "w", "a"]


@_inherit_docstrings
class ZipStore(Store):
"""
Storage class using a ZIP file.
Expand Down