Ejemplo n.º 1
0
    def test_complete_nx_to_gs(self):
        # multi-propery, node propery and edge propty both aligned
        nodes = [
            (0, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
            (1, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
            (2, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
        ]
        edges = [
            (0, 1, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
            (0, 2, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
            (1, 2, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
        ]
        nx_g = self.NXGraph()
        nx_g.update(edges, nodes)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # node property aliged, edge not aliged
        nx_g2 = nx_g.copy()
        nx_g2.add_edge(0, 1, ep4="new propery")
        gs_g2 = g(nx_g2)
        self.assert_convert_success(gs_g2, nx_g2)

        # edge property aliged, node not aliged
        nx_g3 = nx_g.copy()
        nx_g3.add_node(2, vp4="new propery")
        gs_g3 = g(nx_g3)
        self.assert_convert_success(gs_g3, nx_g3)

        # both not aliged
        nx_g4 = nx_g.copy()
        nx_g4.add_edge(0, 1, ep4="new propery")
        nx_g4.add_node(2, vp4="new propery")
        gs_g4 = g(nx_g4)
        self.assert_convert_success(gs_g4, nx_g4)
Ejemplo n.º 2
0
    def test_nx_to_gs_remove_nodes(self):
        nx_g = self.NXGraph()
        nx_g.add_nodes_from(range(10))  # all nodes are int
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)  # success

        nx_g.add_node("str_node")  # add a str node
        with pytest.raises(
            RuntimeError,
            match="The vertex type is not consistent <class 'int'> vs <class 'str'>, can not convert it to arrow graph",
        ):
            gs_g = g(nx_g)  # mixing oid type, failed

        nx_g.remove_node("str_node")  # remove str node, all nodes are int again
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)  # success
Ejemplo n.º 3
0
 def test_error_on_mixing_node_nx_to_gs(self):
     nx_g = self.NXGraph()
     nx_g.add_node(0, weight=1.23)
     nx_g.add_node("zakky", foo="node")
     with pytest.raises(
         RuntimeError,
         match="The vertex type is not consistent <class 'int'> vs <class 'str'>, can not convert it to arrow graph",
     ):
         gs_g = g(nx_g)
Ejemplo n.º 4
0
 def test_int_node_nx_to_gs(self):
     nx_g = self.NXGraph()
     nx_g.add_nodes_from(range(10), foo="star")
     nx_g.add_edges_from(
         [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)],
         weight=3.14,
     )
     gs_g = g(nx_g)
     self.assert_convert_success(gs_g, nx_g)
Ejemplo n.º 5
0
    def setup_class(cls):
        cls.NXGraph = nx.Graph

        data_dir = os.path.expandvars("${GS_TEST_DIR}/ldbc_sample")
        cls.single_label_g = ldbc_sample_single_label(data_dir, False)
        cls.multi_label_g = ldbc_sample_multi_labels(data_dir, False)
        cls.duplicated_oid_g = ldbc_sample_with_duplicated_oid(data_dir, False)

        # FIXME: this is tricky way to create a str gs graph
        les_g = nx.les_miserables_graph()
        cls.str_oid_g = g(les_g)
Ejemplo n.º 6
0
    def test_nx_to_gs_after_modify(self):
        nx_g = self.NXGraph()
        nodes = [
            (0, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
            (1, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
            (2, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
        ]
        # add nodes
        nx_g.add_nodes_from(nodes)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # add_edges
        edges = [
            (0, 1, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
            (0, 2, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
            (1, 2, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
        ]
        nx_g.add_edges_from(edges)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # remove edge
        nx_g.remove_edge(0, 1)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # remove node
        nx_g.remove_node(0)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # clear
        nx_g.clear()
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)
Ejemplo n.º 7
0
 def test_empty_gs_to_nx(self):
     empty_nx = self.NXGraph()
     empty_gs_graph = g(empty_nx)
     nx_g = self.NXGraph(empty_gs_graph)
     self.assert_convert_success(empty_gs_graph, nx_g)
Ejemplo n.º 8
0
 def test_error_on_view_to_gs(self):
     nx_g = self.NXGraph()
     nx_g._graph = None  # graph view always has a _graph attribute
     with pytest.raises(TypeError, match="graph view can not convert to gs graph"):
         gs_g = g(nx_g)
Ejemplo n.º 9
0
 def test_str_node_nx_to_gs(self):
     nx_g = nx.les_miserables_graph()
     gs_g = g(nx_g)
     self.assert_convert_success(gs_g, nx_g)
Ejemplo n.º 10
0
 def test_simple_nx_to_gs(self):
     nx_g = nx.complete_graph(10, create_using=self.NXGraph)
     gs_g = g(nx_g)
     self.assert_convert_success(gs_g, nx_g)
Ejemplo n.º 11
0
 def test_only_contains_nodes_nx_to_gs(self):
     nx_g = self.NXGraph()
     nx_g.add_nodes_from(range(100), type="node")
     gs_g = g(nx_g)
     self.assert_convert_success(gs_g, nx_g)
Ejemplo n.º 12
0
 def test_empty_nx_to_gs(self):
     empty_nx_g = self.NXGraph()
     gs_g = g(empty_nx_g)
     self.assert_convert_success(gs_g, empty_nx_g)