Skip to content

Commit

Permalink
Unify tests for digraph and multidigraph (#43)
Browse files Browse the repository at this point in the history
* Adds support for multigraphs

* Refactors `_is_edge_attr_match`

* Filters relations by __label__ during `_lookup`

* Bundles relation attributes together for lookup

* Refactors and adds inline docs

* Adds tests for multigraph support

* Cleans up inline docs

* Removes slicing list twice to avoid two copies in memory

* Supports WHERE clause for relationships in multigraphs

* Adds test for multigraph with WHERE clause on single edge

* Accounts for WHERE with string node attributes in MultiDiGraphs

* Unifies all unit tests to work with both DiGraphs and MultiDiGraphs

* Completes multidigraph test for WHERE on node attribute
  • Loading branch information
jackboyla authored May 22, 2024
1 parent 4bedf30 commit b2b1771
Show file tree
Hide file tree
Showing 2 changed files with 282 additions and 156 deletions.
6 changes: 4 additions & 2 deletions grandcypher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _is_edge_attr_match(
continue
if host_edges.get(attr) != val:
return False

return True


Expand All @@ -260,7 +260,6 @@ def _aggregate_edge_labels(edges: Dict) -> Dict:
aggregated[edge_id] = attrs
return aggregated


def _get_entity_from_host(
host: Union[nx.DiGraph, nx.MultiDiGraph], entity_name, entity_attribute=None
):
Expand Down Expand Up @@ -330,6 +329,7 @@ def inner(
if isinstance(host, nx.MultiDiGraph):
# if any of the relations between nodes satisfies condition, return True
r_vals = _get_entity_from_host(host, *host_entity_id)
r_vals = [r_vals] if not isinstance(r_vals, list) else r_vals
val = any(operator(r_val, value) for r_val in r_vals)
else:
val = operator(_get_entity_from_host(host, *host_entity_id), value)
Expand Down Expand Up @@ -485,6 +485,7 @@ def _lookup(self, data_paths: List[str], offset_limit) -> Dict[str, List]:

result[data_path] = list(ret)[offset_limit]


return result

def return_clause(self, clause):
Expand Down Expand Up @@ -726,6 +727,7 @@ def _edge_hop_motifs(self, motif: nx.MultiDiGraph) -> List[Tuple[nx.Graph, dict]
if motif.out_degree(n) == 0 and motif.in_degree(n) == 0:
new_motif.add_node(n, **motif.nodes[n])
motifs: List[Tuple[nx.DiGraph, dict]] = [(new_motif, {})]

for u, v, k in motif.edges: # OutMultiEdgeView([('a', 'b', 0)])
new_motifs = []
min_hop = motif.edges[u, v, k]["__min_hop__"]
Expand Down
Loading

0 comments on commit b2b1771

Please sign in to comment.