Skip to content

Commit

Permalink
Add: NetworkGroup.__add__ method. Fixes #200
Browse files Browse the repository at this point in the history
This commit implements the `+` operator for the `NetworkGroup` object
and lets you "add" two `NetworkGroup` objects together.

```python
ng1 = NetworkGroup.load_json("ng1.json")
ng2 = NetworkGroup.load_json("ng2.json")

ng = ng1 + ng2
```
  • Loading branch information
dileep-kishore committed Mar 2, 2021
1 parent cd736f0 commit 195d084
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions micone/main/network_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def __repr__(self) -> str:
n_contexts = len(self.contexts)
return f"<NetworkGroup contexts={n_contexts} nodes={n_nodes} links={n_links}>"

def __add__(self, other: "NetworkGroup") -> "NetworkGroup":
"""Combine two `NetworkGroup` objects and return a new `NetworkGroup` object
The new `NetworkGroup` contains nodes and edges from both the input objects
"""
networks = [*self._networks, *other._networks]
return NetworkGroup(networks)

def _combine_nodes(self, all_nodes: Dict[int, DType]) -> DType:
""" Combine nodes of individual networks into a single list """
nodes: DType = []
Expand Down

0 comments on commit 195d084

Please sign in to comment.