Skip to content

Commit

Permalink
feat: Implement note-related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
auguste-probabl committed Jan 13, 2025
1 parent 7553e74 commit 1fe38e2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
69 changes: 69 additions & 0 deletions skore/src/skore/item/item_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,72 @@ def keys(self) -> list[str]:
A list of all keys in the storage.
"""
return list(self.storage.keys())

def set_item_note(self, key: str, message: str, *, version=-1):
"""Attach a note to key ``key``.
Parameters
----------
key : str
The key of the item to annotate.
May be qualified with a version number through the ``version`` argument.
message : str
The message to be attached.
version : int, default=-1
The version of the key to annotate. Default is the latest version.
Raises
------
KeyError
If the ``(key, version)`` couple does not exist.
"""
try:
self.storage[key][version]["item"]["note"] = message
except IndexError as e:
raise KeyError((key, version)) from e

def get_item_note(self, key: str, *, version=-1) -> str | None:
"""Retrieve a note previously attached to key ``key``.
Parameters
----------
key : str
The key of the annotated item.
May be qualified with a version number through the ``version`` argument.
version : int, default=-1
The version of the annotated key. Default is the latest version.
Returns
-------
The attached note, or None if no note is attached.
Raises
------
KeyError
If no note is attached to the ``(key, version)`` couple.
"""
try:
return self.storage[key][version]["item"]["note"]
except IndexError as e:
raise KeyError((key, version)) from e

def delete_item_note(self, key: str, *, version=-1):
"""Delete a note previously attached to key ``key``.
Parameters
----------
key : str
The key of the annotated item.
May be qualified with a version number through the ``version`` argument.
version : int, default=-1
The version of the annotated key. Default is the latest version.
Raises
------
KeyError
If no note is attached to the ``(key, version)`` couple.
"""
try:
self.storage[key][version]["item"]["note"] = None
except IndexError as e:
raise KeyError((key, version)) from e
8 changes: 5 additions & 3 deletions skore/src/skore/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ def set_note(self, key: str, message: str, *, version=-1):
# Annotate first version of key "key"
>>> project.set_note("key", "message", version=0) # doctest: +SKIP
"""
pass
return self.item_repository.set_item_note(
key=key, message=message, version=version
)

def get_note(self, key: str, *, version=-1) -> Union[str, None]:
"""Retrieve a note previously attached to key ``key``.
Expand Down Expand Up @@ -359,7 +361,7 @@ def get_note(self, key: str, *, version=-1) -> Union[str, None]:
# Retrieve note attached to first version of key "key"
>>> project.get_note("key", version=0) # doctest: +SKIP
"""
pass
return self.item_repository.get_item_note(key=key, version=version)

def delete_note(self, key: str, *, version=-1):
"""Delete a note previously attached to key ``key``.
Expand Down Expand Up @@ -387,4 +389,4 @@ def delete_note(self, key: str, *, version=-1):
# Delete note attached to first version of key "key"
>>> project.delete_note("key", version=0) # doctest: +SKIP
"""
pass
return self.item_repository.delete_item_note(key=key, version=version)

0 comments on commit 1fe38e2

Please sign in to comment.