diff --git a/skore/src/skore/project.py b/skore/src/skore/project.py index e0701deb..666c0360 100644 --- a/skore/src/skore/project.py +++ b/skore/src/skore/project.py @@ -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, it replaces the value with the new one. If `on_error` is "raise", any error stops the execution. If `on_error` is "warn" (or anything other than "raise"), a warning is shown instead. @@ -87,9 +88,9 @@ def put_several( Parameters ---------- - key_to_value : dict[str, Any] + 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" or "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". @@ -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.""" + """Get and returns the value corresponding to `key` from the Project. + Parameters + ---------- + key: str + The key corresponding to the item to get. + + Raises + ------ + KeyError + Renders KeyError if the input key doesn't correspond to any item. + """ item = self.get_item(key) if isinstance(item, PrimitiveItem): @@ -131,15 +142,49 @@ 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.""" + """Get and returns the Item corresponding to `key` from the Project. + Parameters + ---------- + 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. + primitive: Any + Value corresponding to the item. + + Raises + ------ + KeyError + Renders KeyError if the input key doesn't correspond to any item.""" 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. + """ return self.item_repository.keys() def delete_item(self, key: str): - """Delete an item from the Project.""" + """Delete an item from the Project. + Parameters + ---------- + key: str + The key corresponding to the item to delete. + + Raises + ------ + KeyError + Renders KeyError if the input key doesn't correspond to any item. + """ self.item_repository.delete_item(key) def put_view(self, key: str, view: View): @@ -147,15 +192,46 @@ def put_view(self, key: str, view: View): self.view_repository.put_view(key, view) def get_view(self, key: str) -> View: - """Get the view corresponding to `key` from the Project.""" + """Get 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 + Renders KeyError if the input key doesn't correspond to any item. + """ 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 + Renders KeyError if the input key doesn't correspond to any view. + """ 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. + """ return self.view_repository.keys()