Improve NetworkX module import (#21)

* Improve NetworkX module import
* Add Networkx dependencies to Dockerfiles
This commit is contained in:
Marko Budiselić 2020-10-15 09:14:50 +02:00 committed by GitHub
parent 157590a294
commit 48587d6d5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 14 deletions

View File

@ -1,11 +1,21 @@
import sys
import mgp
from collections import OrderedDict
from itertools import chain, repeat
from inspect import cleandoc
from typing import List, Tuple, Optional
from mgp_networkx import MemgraphMultiDiGraph
import networkx as nx
from typing import List, Tuple
try:
import networkx as nx
except ImportError as import_error:
sys.stderr.write((
'\n'
'NOTE: Please install networkx to be able to use graph_analyzer '
'module. Using Python:\n'
+ sys.version +
'\n'))
raise import_error
# Imported last because it also depends on networkx.
from mgp_networkx import MemgraphMultiDiGraph # noqa E402
_MAX_LIST_SIZE = 10

View File

@ -1,7 +1,16 @@
import sys
import mgp
import collections
import networkx as nx
try:
import networkx as nx
except ImportError as import_error:
sys.stderr.write((
'\n'
'NOTE: Please install networkx to be able to use Memgraph NetworkX '
'wrappers. Using Python:\n'
+ sys.version +
'\n'))
raise import_error
class MemgraphAdjlistOuterDict(collections.abc.Mapping):

View File

@ -1,8 +1,22 @@
import sys
import mgp
from mgp_networkx import (MemgraphMultiDiGraph, MemgraphDiGraph,
try:
import networkx as nx
import numpy # noqa E401
import scipy # noqa E401
except ImportError as import_error:
sys.stderr.write((
'\n'
'NOTE: Please install networkx, numpy, scipy to be able to '
'use proxied NetworkX algorithms. E.g., CALL nxalg.pagerank(...).\n'
'Using Python:\n'
+ sys.version +
'\n'))
raise import_error
# Imported last because it also depends on networkx.
from mgp_networkx import (MemgraphMultiDiGraph, MemgraphDiGraph, # noqa: E402
MemgraphMultiGraph, MemgraphGraph,
PropertiesDictionary)
import networkx as nx
# networkx.algorithms.approximation.connectivity.node_connectivity

View File

@ -1,6 +1,15 @@
import sys
import mgp
import networkx as nx
try:
import networkx as nx
except ImportError as import_error:
sys.stderr.write(
'\n'
'NOTE: Please install networkx to be able to use wcc module.\n'
'Using Python:\n'
+ sys.version +
'\n')
raise import_error
@mgp.read_proc
@ -28,8 +37,10 @@ def get_components(vertices: mgp.List[mgp.Vertex],
vertices labeled `Person` and edges between such vertices can be obtained
using the following openCypher query:
MATCH (n:Person)-[e]->(m:Person) WITH collect(n) AS nodes, collect(e) AS edges
CALL wcc.get_components(nodes, edges) YIELD * RETURN n_components, components;
MATCH (n:Person)-[e]->(m:Person)
WITH collect(n) AS nodes, collect(e) AS edges
CALL wcc.get_components(nodes, edges) YIELD *
RETURN n_components, components;
'''
g = nx.DiGraph()
g.add_nodes_from(vertices)

View File

@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pip3 install networkx
RUN pip3 install networkx==2.4 numpy==1.19.2 scipy==1.5.2
COPY ${deb_release} /

View File

@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pip3 install networkx
RUN pip3 install networkx==2.4 numpy==1.19.2 scipy==1.5.2
COPY ${deb_release} /