Skip to content

Commit

Permalink
Add unit test for graph extending data.
Browse files Browse the repository at this point in the history
Committed-by: SighingSnow from Dev container

.

Committed-by: SighingSnow from Dev container

Committed-by: SighingSnow from Dev container

Committed-by: SighingSnow from Dev container
  • Loading branch information
SighingSnow committed Nov 6, 2023
1 parent a16359d commit 193d2f1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
8 changes: 5 additions & 3 deletions python/graphscope/framework/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def __init__(
self._compact_edges = compact_edges
self._use_perfect_hash = use_perfect_hash
# for need to extend label in 'eager mode' when add_vertices and add_edges
# 0 - not extending label
# 0 - not extending label
# 1 - extend vertex label
# 2 - extend edge label
self._extend_label_data = 0
Expand Down Expand Up @@ -517,8 +517,10 @@ def add_vertices(
# currently not support local_vertex_map
if label in self._v_labels:
self._extend_label_data = 1
warnings.warn(f"Label {label} already existed in graph"
", origin label data will be extend.")
warnings.warn(
f"Label {label} already existed in graph"
", origin label data will be extend."
)
unsealed_vertices_and_edges = deepcopy(self._unsealed_vertices_and_edges)
vertex_label = VertexLabel(
label=label,
Expand Down
47 changes: 47 additions & 0 deletions python/graphscope/tests/unittest/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os

import numpy as np
import pandas as pd
import pytest

import graphscope
Expand Down Expand Up @@ -298,6 +299,52 @@ def test_add_vertices_edges(graphscope_session):
assert graph.schema.edge_labels == ["knows", "created"]


@pytest.mark.skip("unlock this when update")
def test_extend_vertices_edges(graphscope_session):
prefix = os.path.expandvars("${GS_TEST_DIR}/")
verts = pd.read_csv(f"{prefix}/p2p_v.csv")
edges = pd.read_csv(f"{prefix}/p2p_e.csv")
test_list = ["v11308", "v50089", "v60129"]

g1 = graphscope_session.g(oid_type="std::string")
g1 = g1.add_vertices(Loader(verts), "person")
g1 = g1.add_edges(Loader(edges), "knows", src_label="person", dst_label="person")

g2 = graphscope_session.g(oid_type="std::string")
g2 = g2.add_vertices(Loader(verts[:12980]), "person")
g2 = g2.add_vertices(Loader(verts[12980:31530]), "person")
g2 = g2.add_vertices(Loader(verts[31530:]), "person")

g2 = g2.add_edges(
Loader(edges[:2302]), "knows", src_label="person", dst_label="person"
)
g2 = g2.add_edges(
Loader(edges[2302:40021]), "knows", src_label="person", dst_label="person"
)
g2 = g2.add_edges(
Loader(edges[40021:]), "knows", src_label="person", dst_label="person"
)

sg1 = g1.project(vertices={"person": ["id"]}, edges={"knows": ["dist"]})
sg2 = g2.project(vertices={"person": ["id"]}, edges={"knows": ["dist"]})
for src in test_list:
res1 = graphscope.sssp(sg1, src=src, weight="dist")
res2 = graphscope.sssp(sg2, src=src, weight="dist")
df1 = res1.to_dataframe(selector={"id": "v.id", "r": "r"}).sort_values(
by=["id"], ignore_index=True
)
df2 = res2.to_dataframe(selector={"id": "v.id", "r": "r"}).sort_values(
by=["id"], ignore_index=True
)
if not df1.equals(df2):
pytest.raises(
AssertionError, "different sssp result got after extending graph data"
)

del g1, g2, sg1, sg2
print("pass graph extending test")


def test_complicated_add_edges(graphscope_session):
prefix = os.path.expandvars("${GS_TEST_DIR}/modern_graph")
graph = graphscope_session.g()
Expand Down

0 comments on commit 193d2f1

Please sign in to comment.