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

Consistent conversion to undirected graphs #301

Merged
merged 13 commits into from
Apr 16, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
  • Loading branch information
pre-commit-ci[bot] committed Apr 10, 2023
commit 1e3b6090c625662d62174bef82f565bdad805157
13 changes: 7 additions & 6 deletions graphein/ml/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,11 @@ def convert_nx_to_pyg(self, G: nx.Graph) -> Data:

# Add edge features
edge_feature_names = list(G.edges(data=True))[0][2].keys()
edge_feature_names = list(filter(
lambda x: x in self.columns and x != 'kind', edge_feature_names
))
edge_feature_names = list(
filter(
lambda x: x in self.columns and x != "kind", edge_feature_names
)
)
for i, (_, _, feat_dict) in enumerate(G.edges(data=True)):
for key, value in feat_dict.items():
key = str(key)
Expand Down Expand Up @@ -339,7 +341,7 @@ def convert_nx_to_pyg(self, G: nx.Graph) -> Data:
edge_index, edge_features = to_undirected(
data.edge_index,
[getattr(data, attr) for attr in edge_feature_names],
data.num_nodes
data.num_nodes,
)
data.edge_index = edge_index
for attr, val in zip(edge_feature_names, edge_features):
Expand All @@ -349,8 +351,7 @@ def convert_nx_to_pyg(self, G: nx.Graph) -> Data:
for kind in set(kind_strs):
key = f"edge_index_{kind}"
edge_index_kind = to_undirected(
getattr(data, key),
num_nodes=data.num_nodes
getattr(data, key), num_nodes=data.num_nodes
)
setattr(data, key, edge_index_kind)

Expand Down