Skip to content

Commit

Permalink
[python] Add CollectionBase.members (#2795) (#2849)
Browse files Browse the repository at this point in the history
Co-authored-by: nguyenv <[email protected]>
  • Loading branch information
github-actions[bot] and nguyenv committed Aug 6, 2024
1 parent f40e84e commit 8779032
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apis/python/src/tiledbsoma/_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ def set(
)
return self

def members(self) -> Dict[str, Tuple[str, str]]:
"""Get a mapping of {member_name: (uri, soma_object_type)}"""
handle = cast(_tdb_handles.SOMAGroupWrapper[Any], self._handle)
return handle.members()

def __setitem__(self, key: str, value: CollectionElementType) -> None:
"""Default collection __setattr__"""
self.set(key, value, use_relative_uri=None)
Expand Down
4 changes: 4 additions & 0 deletions apis/python/src/tiledbsoma/_tdb_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Type,
TypeVar,
Union,
cast,
)

import attrs
Expand Down Expand Up @@ -296,6 +297,9 @@ def _do_initial_reads(self, group: clib.SOMAGroup) -> None:
def meta(self) -> "MetadataWrapper":
return self.metadata

def members(self) -> Dict[str, Tuple[str, str]]:
return cast(Dict[str, Tuple[str, str]], self._handle.members())


class CollectionWrapper(SOMAGroupWrapper[clib.SOMACollection]):
"""Wrapper around a Pybind11 CollectionWrapper handle."""
Expand Down
1 change: 1 addition & 0 deletions apis/python/tests/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def test_collection_mapping(soma_object, tmp_path):
assert list(k for k in c) == list(c.keys())
assert len(c) == 1
assert [k for k in c] == ["mumble"]
assert c.members() == {"mumble": (soma_object.uri, "SOMACollection")}

# TEMPORARY: This should no longer raise an error once TileDB supports
# replacing an existing group member.
Expand Down

0 comments on commit 8779032

Please sign in to comment.