Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(project): Add docstrings to functions in project #541

Merged
merged 23 commits into from
Oct 22, 2024
Merged
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8d0f9f1
(doc) add docstrings to functions in project
MarieS-WiMLDS Oct 18, 2024
0fc1398
Merge branch 'main' into 535-docstring_project
MarieS-WiMLDS Oct 18, 2024
b6801ae
(doc) project: improve sentences + respect numpy convention
MarieS-WiMLDS Oct 21, 2024
c5256ad
(doc) project: remove typo
MarieS-WiMLDS Oct 21, 2024
5331889
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
cf043c3
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
d4494d2
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
7e79250
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
e6d1671
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
57e098f
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
7d17197
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
215251e
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
0205ff0
(doc) project: returns to get in func description
MarieS-WiMLDS Oct 21, 2024
20e7837
(doc) project: concise list_keys description
MarieS-WiMLDS Oct 21, 2024
df4262b
(doc) project: remove attributes, as it's only for classes
MarieS-WiMLDS Oct 21, 2024
8ebf15c
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
c536310
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
1962c41
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
71db3ee
Update skore/src/skore/project.py
MarieS-WiMLDS Oct 21, 2024
aa08266
Merge branch 'main' into 535-docstring_project
MarieS-WiMLDS Oct 21, 2024
6d1958e
Merge branch 'main' into 535-docstring_project
MarieS-WiMLDS Oct 21, 2024
a7def51
(doc) project: remore trailing whitespace
MarieS-WiMLDS Oct 21, 2024
d55c772
Merge branch 'main' into 535-docstring_project
thomass-dev Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 85 additions & 9 deletions skore/src/skore/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(
@singledispatchmethod
def put(self, key: str, value: Any, on_error: Literal["warn", "raise"] = "warn"):
"""Add a value to the Project.
If an item with the same key already exists, its value is replaced by the new one.

If `on_error` is "raise", any error stops the execution. If `on_error`
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
is "warn" (or anything other than "raise"), a warning is shown instead.
Expand All @@ -51,7 +52,7 @@ def put(self, key: str, value: Any, on_error: Literal["warn", "raise"] = "warn")
The key to associate with `value` in the Project. Must be a string.
value : Any
The value to associate with `key` in the Project.
on_error : "warn" or "raise", optional
on_error : {"warn", "raise"}, optional
Upon error (e.g. if the key is not a string), whether to raise an error or
to print a warning. Default is "warn".

Expand Down Expand Up @@ -89,7 +90,7 @@ def put_several(
----------
key_to_value : dict[str, Any]
The key-value pairs to put in the Project. Keys must be strings.
on_error : "warn" or "raise", optional
on_error : {"warn", "raise"}, optional
Upon error (e.g. if a key is not a string), whether to raise an error or
to print a warning. Default is "warn".

Expand All @@ -112,7 +113,17 @@ def put_item(self, key: str, item: Item):
self.item_repository.put_item(key, item)

def get(self, key: str) -> Any:
"""Get the value corresponding to `key` from the Project."""
"""Returns the value corresponding to `key` from the Project..
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
Parameters
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
----------
key : str
The key corresponding to the item to get.

Raises
------
KeyError
Raises a KeyError if the key does not correspond to any item.
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
"""
item = self.get_item(key)

if isinstance(item, PrimitiveItem):
Expand All @@ -131,31 +142,96 @@ def get(self, key: str) -> Any:
raise ValueError(f"Item {item} is not a known item type.")

def get_item(self, key: str) -> Item:
"""Add the Item corresponding to `key` from the Project."""
"""Returns the item corresponding to key from the Project.
Parameters
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
----------
key: str
The key corresponding to the item to get.

Attributes
----------
created_at : DateTime
DateTime when the item was created.
updated_at : DateTime
DateTime of the last modification.
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
primitive : Any
Value corresponding to the item.
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved

Raises
------
KeyError
Raises a KeyError if the key does not correspond to any item."""
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
return self.item_repository.get_item(key)

def list_item_keys(self) -> list[str]:
"""List all item keys in the Project."""
"""List all item keys in the Project.
Returns
-------
List
Returns the list of items keys. Each key is a string.
If the project contains no item, returns an empty list.
"""
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
return self.item_repository.keys()

def delete_item(self, key: str):
"""Delete an item from the Project."""
"""Deletes the item corresponding to `key` from the Project.
Parameters
----------
key : str
The key corresponding to the item to delete.

Raises
------
KeyError
Raises a KeyError if the key does not correspond to any item.
"""
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
self.item_repository.delete_item(key)

def put_view(self, key: str, view: View):
"""Add a view to the Project."""
self.view_repository.put_view(key, view)

def get_view(self, key: str) -> View:
"""Get the view corresponding to `key` from the Project."""
"""Returns the view corresponding to `key` from the Project.
Parameters
----------
key : str
The key corresponding to the item to get.

Attributes
----------
layout : List[str]
A list of the keys of items, in the same order as displayed.

Raises
------
KeyError
Raises a KeyError if the key does not correspond to any view.
"""
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
return self.view_repository.get_view(key)

def delete_view(self, key: str):
"""Delete the view corresponding to `key` from the Project."""
"""Delete the view corresponding to `key` from the Project.
Parameters
----------
key : str
The key corresponding to the view to delete.

Raises
------
KeyError
Raises a KeyError if the key does not correspond to any view.
"""
MarieS-WiMLDS marked this conversation as resolved.
Show resolved Hide resolved
return self.view_repository.delete_view(key)

def list_view_keys(self) -> list[str]:
"""List all view keys in the Project."""
"""List all view keys in the Project.
Returns
-------
List
Returns the list of view keys. Each key is a string.
If the project contains no view, returns an empty list.
"""
augustebaum marked this conversation as resolved.
Show resolved Hide resolved
return self.view_repository.keys()


Expand Down