Skip to content

Commit

Permalink
read_node -> get_node
Browse files Browse the repository at this point in the history
  • Loading branch information
d-v-b committed Feb 2, 2025
1 parent e546519 commit 24eab3a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/zarr/api/asynchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
create_hierarchy,
create_nodes,
create_rooted_hierarchy,
read_node,
get_node,
)
from zarr.core.metadata import ArrayMetadataDict, ArrayV2Metadata, ArrayV3Metadata
from zarr.core.metadata.v2 import _default_compressor, _default_filters
Expand Down Expand Up @@ -63,6 +63,7 @@
"empty_like",
"full",
"full_like",
"get_node",
"group",
"load",
"ones",
Expand All @@ -72,7 +73,6 @@
"open_consolidated",
"open_group",
"open_like",
"read_node",
"save",
"save_array",
"save_group",
Expand Down
8 changes: 4 additions & 4 deletions src/zarr/api/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"empty_like",
"full",
"full_like",
"get_node",
"group",
"load",
"ones",
Expand All @@ -65,7 +66,6 @@
"open_consolidated",
"open_group",
"open_like",
"read_node",
"save",
"save_array",
"save_group",
Expand Down Expand Up @@ -1247,9 +1247,9 @@ def create_rooted_hierarchy(
return _parse_async_node(async_node)


def read_node(store: Store, path: str, zarr_format: ZarrFormat) -> Array | Group:
def get_node(store: Store, path: str, zarr_format: ZarrFormat) -> Array | Group:
"""
Read an Array or Group from a path in a Store.
Get an Array or Group from a path in a Store.
Parameters
----------
Expand All @@ -1266,5 +1266,5 @@ def read_node(store: Store, path: str, zarr_format: ZarrFormat) -> Array | Group
"""

return _parse_async_node(
sync(async_api.read_node(store=store, path=path, zarr_format=zarr_format))
sync(async_api.get_node(store=store, path=path, zarr_format=zarr_format))
)
14 changes: 7 additions & 7 deletions src/zarr/core/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ async def getitem(
if self.metadata.consolidated_metadata is not None:
return self._getitem_consolidated(store_path, key, prefix=self.name)
try:
return await read_node(
return await get_node(
store=store_path.store, path=store_path.path, zarr_format=self.metadata.zarr_format
)
except FileNotFoundError as e:
Expand Down Expand Up @@ -3430,7 +3430,7 @@ def _build_node(
raise ValueError(f"Unexpected metadata type: {type(metadata)}") # pragma: no cover


async def _read_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
async def _get_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata] | AsyncGroup:
"""
Read a Zarr v2 AsyncArray or AsyncGroup from a path in a Store.
Expand All @@ -3449,7 +3449,7 @@ async def _read_node_v2(store: Store, path: str) -> AsyncArray[ArrayV2Metadata]
return _build_node(store=store, path=path, metadata=metadata)


async def _read_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
async def _get_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata] | AsyncGroup:
"""
Read a Zarr v3 AsyncArray or AsyncGroup from a path in a Store.
Expand All @@ -3468,11 +3468,11 @@ async def _read_node_v3(store: Store, path: str) -> AsyncArray[ArrayV3Metadata]
return _build_node(store=store, path=path, metadata=metadata)


async def read_node(
async def get_node(
store: Store, path: str, zarr_format: ZarrFormat
) -> AsyncArray[ArrayV2Metadata] | AsyncArray[ArrayV3Metadata] | AsyncGroup:
"""
Read an AsyncArray or AsyncGroup from a path in a Store.
Get an AsyncArray or AsyncGroup from a path in a Store.
Parameters
----------
Expand All @@ -3490,9 +3490,9 @@ async def read_node(

match zarr_format:
case 2:
return await _read_node_v2(store=store, path=path)
return await _get_node_v2(store=store, path=path)
case 3:
return await _read_node_v3(store=store, path=path)
return await _get_node_v3(store=store, path=path)
case _: # pragma: no cover
raise ValueError(f"Unexpected zarr format: {zarr_format}") # pragma: no cover

Expand Down
8 changes: 4 additions & 4 deletions tests/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import zarr.storage
from zarr import Array, AsyncArray, AsyncGroup, Group
from zarr.abc.store import Store
from zarr.api.synchronous import read_node
from zarr.api.synchronous import get_node
from zarr.core._info import GroupInfo
from zarr.core.buffer import default_buffer_prototype
from zarr.core.config import config as zarr_config
Expand Down Expand Up @@ -1564,13 +1564,13 @@ async def test_create_hierarchy(
observed_nodes = {a.path.removeprefix(path + "/"): a for a in created}

if not overwrite:
extra_group = read_node(
extra_group = get_node(
store=store, path=_join_paths([path, "group/extra"]), zarr_format=zarr_format
)
assert extra_group.metadata.attributes == {"path": "group/extra"}
else:
with pytest.raises(FileNotFoundError):
read_node(store=store, path=_join_paths([path, "group/extra"]), zarr_format=zarr_format)
get_node(store=store, path=_join_paths([path, "group/extra"]), zarr_format=zarr_format)
assert expected_meta == {k: v.metadata for k, v in observed_nodes.items()}


Expand Down Expand Up @@ -1628,7 +1628,7 @@ async def test_create_hierarchy_existing_nodes(

# ensure that the extant metadata was not overwritten
assert (
read_node(store=store, path=_join_paths([path, extant_node_path]), zarr_format=zarr_format)
get_node(store=store, path=_join_paths([path, extant_node_path]), zarr_format=zarr_format)
).metadata.attributes == {"extant": True}


Expand Down

0 comments on commit 24eab3a

Please sign in to comment.