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

add integer support to balance algorithm; apply formatting #1898

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 9 additions & 8 deletions python/python/raphtory/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ConstProperties(object):
"""A view of constant properties of an entity"""

def __contains__(self, key):
"""Return key in self."""
"""Return bool(key in self)."""

def __eq__(self, value):
"""Return self==value."""
Expand Down Expand Up @@ -220,11 +220,12 @@ class DiskGraphStorage(object):
def load_from_parquets(
graph_dir,
layer_parquet_cols,
node_properties,
chunk_size,
t_props_chunk_size,
num_threads,
node_type_col,
node_properties=None,
chunk_size=10000000,
t_props_chunk_size=10000000,
num_threads=4,
node_type_col=None,
node_id_col=None,
): ...
def load_node_const_properties(self, location, col_names=None, chunk_size=None): ...
def merge_by_sorted_gids(self, other, graph_dir):
Expand Down Expand Up @@ -4498,7 +4499,7 @@ class Properties(object):
"""A view of the properties of an entity"""

def __contains__(self, key):
"""Return key in self."""
"""Return bool(key in self)."""

def __eq__(self, value):
"""Return self==value."""
Expand Down Expand Up @@ -4685,7 +4686,7 @@ class TemporalProperties(object):
"""A view of the temporal properties of an entity"""

def __contains__(self, key):
"""Return key in self."""
"""Return bool(key in self)."""

def __eq__(self, value):
"""Return self==value."""
Expand Down
2 changes: 1 addition & 1 deletion python/python/raphtory/algorithms/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Matching(object):
"""True if self else False"""

def __contains__(self, key):
"""Return key in self."""
"""Return bool(key in self)."""

def __iter__(self):
"""Implement iter(self)."""
Expand Down
24 changes: 12 additions & 12 deletions raphtory/src/algorithms/metrics/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
task_runner::TaskRunner,
},
},
prelude::{EdgeViewOps, GraphViewOps, NodeViewOps, PropUnwrap},
prelude::{EdgeViewOps, GraphViewOps, NodeViewOps},
};
use ordered_float::OrderedFloat;

Expand Down Expand Up @@ -58,7 +58,7 @@ fn balance_per_node<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>, C
prop.temporal().get(name).map(|val| {
val.values()
.into_iter()
.map(|valval| valval.into_f64().unwrap_or(0.0f64))
.map(|valval| valval.as_f64().unwrap_or(0.0f64))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this algorithm have a check for the type of the property instead of just returning all 0 if it happens to be a string or something else that can't be converted to float?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative is that edge weights default to 1. @miratepuffin @Alnaimi- any thoughts?

.sum::<f64>()
})
})
Expand All @@ -70,7 +70,7 @@ fn balance_per_node<'graph, G: GraphViewOps<'graph>, GH: GraphViewOps<'graph>, C
prop.temporal().get(name).map(|val| {
val.values()
.into_iter()
.map(|valval| valval.into_f64().unwrap_or(0.0f64))
.map(|valval| valval.as_f64().unwrap_or(0.0f64))
.sum::<f64>()
})
})
Expand Down Expand Up @@ -144,14 +144,14 @@ mod sum_weight_test {
let graph = Graph::new();

let vs = vec![
("1", "2", 10.0, 1),
("1", "4", 20.0, 2),
("2", "3", 5.0, 3),
("3", "2", 2.0, 4),
("3", "1", 1.0, 5),
("4", "3", 10.0, 6),
("4", "1", 5.0, 7),
("1", "5", 2.0, 8),
("1", "2", 10, 1),
("1", "4", 20, 2),
("2", "3", 5, 3),
("3", "2", 2, 4),
("3", "1", 1, 5),
("4", "3", 10, 6),
("4", "1", 5, 7),
("1", "5", 2, 8),
];

for (src, dst, val, time) in &vs {
Expand All @@ -160,7 +160,7 @@ mod sum_weight_test {
*time,
*src,
*dst,
[("value_dec".to_string(), Prop::F64(*val))],
[("value_dec".to_string(), Prop::I32(*val))],
None,
)
.expect("Couldnt add edge");
Expand Down
Loading