Skip to content

Commit

Permalink
fix some of the stub warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ljeub-pometry committed Dec 18, 2024
1 parent ebd3899 commit 2908592
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 33 deletions.
46 changes: 29 additions & 17 deletions python/python/raphtory/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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]:
"""
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion raphtory/src/db/api/view/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,6 @@ mod test {
.filter_map(|v| v.as_u64())
.collect_vec(),
vec![1]
)
);
}
}
7 changes: 5 additions & 2 deletions raphtory/src/python/graph/algorithm_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<(
Expand All @@ -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<String>> {
self.0.group_by()
}
Expand Down
32 changes: 19 additions & 13 deletions raphtory/src/python/graph/properties/constant_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArcStr> {
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:
Expand All @@ -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<Prop> {
// Fixme: Add option to specify default?
self.props.get(key)
Expand All @@ -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<ArcStr, Prop> {
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()
}
Expand Down

0 comments on commit 2908592

Please sign in to comment.