Skip to content

Commit

Permalink
Add get_annotations to a sample resource
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorjerse committed Nov 22, 2023
1 parent 1f22257 commit ff2e69d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Added
-----
- Add ``set_annotations`` on ``Sample`` resource to allow bulk annotation
update
- Add ``get_annotations`` on ``Sample`` which returns all annotations on a
sample as a dictionary


===================
Expand Down
7 changes: 7 additions & 0 deletions src/resdk/resources/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ def set_annotation(self, full_path: str, value) -> Optional["AnnotationValue"]:
)
return annotation_value

def get_annotations(self) -> Dict[str, Any]:
"""Get all annotations for the given sample in a dictionary."""
return {
str(annotation.field): annotation.value
for annotation in self.annotations.all()
}

def set_annotations(self, annotations: Dict[str, Any]):
"""Bulk set annotations on the sample."""
payload = [
Expand Down

0 comments on commit ff2e69d

Please sign in to comment.