Skip to content

Commit

Permalink
Feature: Top level V3 API (#1884)
Browse files Browse the repository at this point in the history
* feature(api): add top level synchronous and asynchronous api

* add group/open_group

* minor doc improvement

* sync with v3 branch

* fix mypy errors

* progress integrating store mode

* basic tests are passing

* docs and missing store utils file

* fix parse shapelike test

* fix bad merge

* respond to reviews
  • Loading branch information
jhamman authored Jun 7, 2024
1 parent 661acb3 commit ee30347
Show file tree
Hide file tree
Showing 17 changed files with 2,167 additions and 64 deletions.
88 changes: 61 additions & 27 deletions src/zarr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
from __future__ import annotations

import zarr.codecs # noqa: F401
from zarr._version import version as __version__
from zarr.api.synchronous import (
array,
consolidate_metadata,
copy,
copy_all,
copy_store,
create,
empty,
empty_like,
full,
full_like,
group,
load,
ones,
ones_like,
open,
open_array,
open_consolidated,
open_group,
open_like,
save,
save_array,
save_group,
tree,
zeros,
zeros_like,
)
from zarr.array import Array, AsyncArray
from zarr.config import config # noqa: F401
from zarr.config import config
from zarr.group import AsyncGroup, Group
from zarr.store import (
StoreLike,
make_store_path,
)
from zarr.sync import sync as _sync

# in case setuptools scm screw up and find version to be 0.0.0
assert not __version__.startswith("0.0.0")


async def open_auto_async(store: StoreLike) -> AsyncArray | AsyncGroup:
store_path = make_store_path(store)
try:
return await AsyncArray.open(store_path)
except KeyError:
return await AsyncGroup.open(store_path)


def open_auto(store: StoreLike) -> Array | Group:
object = _sync(
open_auto_async(store),
)
if isinstance(object, AsyncArray):
return Array(object)
if isinstance(object, AsyncGroup):
return Group(object)
raise TypeError(f"Unexpected object type. Got {type(object)}.")
__all__ = [
"__version__",
"config",
"Array",
"AsyncArray",
"Group",
"AsyncGroup",
"tree",
"array",
"consolidate_metadata",
"copy",
"copy_all",
"copy_store",
"create",
"empty",
"empty_like",
"full",
"full_like",
"group",
"load",
"ones",
"ones_like",
"open",
"open_array",
"open_consolidated",
"open_group",
"open_like",
"save",
"save_array",
"save_group",
"zeros",
"zeros_like",
]
Empty file added src/zarr/api/__init__.py
Empty file.
Loading

0 comments on commit ee30347

Please sign in to comment.