From 29085920fc87aa802cb840e9cbb42d70ad32d3dd Mon Sep 17 00:00:00 2001 From: Lucas Jeub Date: Wed, 18 Dec 2024 08:59:10 +0100 Subject: [PATCH] fix some of the stub warnings --- python/python/raphtory/__init__.pyi | 46 ++++++++++++------- raphtory/src/db/api/view/internal/mod.rs | 2 +- raphtory/src/python/graph/algorithm_result.rs | 7 ++- .../python/graph/properties/constant_props.rs | 32 +++++++------ 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/python/python/raphtory/__init__.pyi b/python/python/raphtory/__init__.pyi index 72307562f..e053cfd6c 100644 --- a/python/python/raphtory/__init__.pyi +++ b/python/python/raphtory/__init__.pyi @@ -61,13 +61,13 @@ class AlgorithmResult(object): dict[str, Any]: a dict with node names and values """ - def group_by(self): + def group_by(self) -> dict[Any, list[str]]: """ Groups the `AlgorithmResult` by its values. Returns: - A `HashMap` where keys are unique values from the `AlgorithmResult` and values are vectors - containing keys of type `H` that share the same value. + dict[Any, list[str]]: A mapping where keys are unique values from the `AlgorithmResult` and values are lists of nodes + that share the same value. """ def max(self) -> Tuple[Node, Any]: @@ -79,7 +79,12 @@ class AlgorithmResult(object): """ def median(self): - """Returns a tuple of the median result with its key""" + """ + Returns a tuple of the median result with its key + + Returns: + Optional[Tuple[Node, Any]]: The node with median value or `None` if there are no nodes. + """ def min(self) -> Tuple[Node, Any]: """ @@ -185,42 +190,49 @@ class ConstProperties(object): def __repr__(self): """Return repr(self).""" - def as_dict(self): + def as_dict(self) -> dict[str, PropValue]: """ as_dict() -> dict[str, Any] convert the properties view to a python dict + + Returns: + dict[str, PropValue]: """ - def get(self, key: Any): + def get(self, key: str): """ - get(key: str) -> Any | None + get property value by key Arguments: - key: the name of the property + key (str): the name of the property - get property value by key (returns `None` if key does not exist) + Returns: + PropValue | None: the property value or `None` if value for `key` does not exist """ - def items(self): + def items(self) -> list[Tuple[str, PropValue]]: """ - items() -> list[tuple[str, Any]] - lists the property keys together with the corresponding value - """ - def keys(self): + Returns: + list[Tuple[str, PropValue]]: the property keys with corresponding values """ - keys() -> list[str] + def keys(self) -> list[str]: + """ lists the available property keys + + Returns: + list[str]: the property keys """ def values(self): """ - values() -> list[Any] - lists the property values + + Returns: + list | Array: the property values """ class DiskGraphStorage(object): diff --git a/raphtory/src/db/api/view/internal/mod.rs b/raphtory/src/db/api/view/internal/mod.rs index f4d263e07..1ad02c59b 100644 --- a/raphtory/src/db/api/view/internal/mod.rs +++ b/raphtory/src/db/api/view/internal/mod.rs @@ -168,6 +168,6 @@ mod test { .filter_map(|v| v.as_u64()) .collect_vec(), vec![1] - ) + ); } } diff --git a/raphtory/src/python/graph/algorithm_result.rs b/raphtory/src/python/graph/algorithm_result.rs index 52c08740a..9a3cca301 100644 --- a/raphtory/src/python/graph/algorithm_result.rs +++ b/raphtory/src/python/graph/algorithm_result.rs @@ -246,6 +246,9 @@ macro_rules! py_algorithm_result_partial_ord { } /// Returns a tuple of the median result with its key + /// + /// Returns: + /// Optional[Tuple[Node, Any]]: The node with median value or `None` if there are no nodes. fn median( &self, ) -> Option<( @@ -267,8 +270,8 @@ macro_rules! py_algorithm_result_new_ord_hash_eq { /// Groups the `AlgorithmResult` by its values. /// /// Returns: - /// A `HashMap` where keys are unique values from the `AlgorithmResult` and values are vectors - /// containing keys of type `H` that share the same value. + /// dict[Any, list[str]]: A mapping where keys are unique values from the `AlgorithmResult` and values are lists of nodes + /// that share the same value. fn group_by(&self) -> std::collections::HashMap<$rustValue, Vec> { self.0.group_by() } diff --git a/raphtory/src/python/graph/properties/constant_props.rs b/raphtory/src/python/graph/properties/constant_props.rs index 5c4f208d3..90cb45a9a 100644 --- a/raphtory/src/python/graph/properties/constant_props.rs +++ b/raphtory/src/python/graph/properties/constant_props.rs @@ -48,29 +48,30 @@ py_eq!(PyConstantProperties, PyPropsComp); #[pymethods] impl PyConstantProperties { - /// keys() -> list[str] - /// /// lists the available property keys + /// + /// Returns: + /// list[str]: the property keys pub fn keys(&self) -> Vec { self.props.keys().collect() } - /// values() -> list[Any] - /// /// lists the property values + /// + /// Returns: + /// list | Array: the property values pub fn values(&self) -> NumpyArray { self.props.values().collect() } - /// items() -> list[tuple[str, Any]] - /// /// lists the property keys together with the corresponding value + /// + /// Returns: + /// list[Tuple[str, PropValue]]: the property keys with corresponding values pub fn items(&self) -> Vec<(ArcStr, Prop)> { self.props.iter().collect() } - /// __getitem__(key: str) -> Any - /// /// get property value by key /// /// Raises: @@ -81,12 +82,13 @@ impl PyConstantProperties { .ok_or(PyKeyError::new_err("No such property")) } - /// get(key: str) -> Any | None + /// get property value by key /// /// Arguments: - /// key: the name of the property + /// key (str): the name of the property /// - /// get property value by key (returns `None` if key does not exist) + /// Returns: + /// PropValue | None: the property value or `None` if value for `key` does not exist pub fn get(&self, key: &str) -> Option { // Fixme: Add option to specify default? self.props.get(key) @@ -95,13 +97,17 @@ impl PyConstantProperties { /// as_dict() -> dict[str, Any] /// /// convert the properties view to a python dict + /// + /// Returns: + /// dict[str, PropValue]: pub fn as_dict(&self) -> HashMap { self.props.as_map() } - /// __iter__() -> Iterator[str] - /// /// iterate over property keys + /// + /// Returns: + /// Iterator[str]: keys iterator pub fn __iter__(&self) -> PyGenericIterator { self.keys().into_iter().into() }