Skip to content

Commit 6480da6

Browse files
authored
Merge pull request #546 from FlorentinD/drop-graphs-from-str
Allow gds.graph.drop by graph name
2 parents f8228c9 + 25ebde4 commit 6480da6

File tree

9 files changed

+38
-40
lines changed

9 files changed

+38
-40
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
## Improvements
1818

1919
* Expose user facing custom types so that they can be directly imported from `graphdatascience`.
20+
* Allow dropping graphs through `gds.graph.drop` by name and not only based on `Graph` objects.
2021

2122

2223
## Other changes

graphdatascience/graph/graph_proc_runner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,20 @@ def ogbl(self) -> OGBLLoader:
294294
self._namespace += ".ogbl"
295295
return OGBLLoader(self._query_runner, self._namespace, self._server_version)
296296

297-
@graph_type_check
298297
def drop(
299298
self,
300-
G: Graph,
299+
graph: Union[Graph, str],
301300
failIfMissing: bool = False,
302301
dbName: str = "",
303302
username: Optional[str] = None,
304303
) -> Optional["Series[Any]"]:
305304
self._namespace += ".drop"
306305

306+
if isinstance(graph, Graph):
307+
graph = graph.name()
308+
307309
params = CallParameters(
308-
graph_name=G.name(),
310+
graph_name=graph,
309311
fail_if_missing=failIfMissing,
310312
db_name=dbName,
311313
)

graphdatascience/tests/integration/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def clean_up(gds: GraphDataScience) -> Generator[None, None, None]:
110110

111111
res = gds.graph.list()
112112
for graph_name in res["graphName"]:
113-
gds.graph.get(graph_name).drop(failIfMissing=True)
113+
gds.graph.drop(graph_name, failIfMissing=True)
114114

115115
res = gds.pipeline.list() if gds.server_version() >= ServerVersion(2, 5, 0) else gds.beta.pipeline.list()
116116
for pipeline_name in res["pipelineName"]:

graphdatascience/tests/integration/test_edge_embedding_model.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from graphdatascience.graph_data_science import GraphDataScience
66
from graphdatascience.model.simple_rel_embedding_model import SimpleRelEmbeddingModel
7-
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
87
from graphdatascience.server_version.server_version import ServerVersion
98

109
GRAPH_NAME = "g"
@@ -21,9 +20,9 @@
2120

2221

2322
@pytest.fixture(autouse=True)
24-
def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
23+
def run_around_tests(gds: GraphDataScience) -> Generator[None, None, None]:
2524
# Runs before each test
26-
runner.run_cypher(
25+
gds.run_cypher(
2726
"""
2827
CREATE
2928
(a: Node {x: 1, y: 2, z: [42.1, 131.0, 12.99]}),
@@ -39,8 +38,8 @@ def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
3938
yield # Test runs here
4039

4140
# Runs after each test
42-
runner.run_cypher("MATCH (n) DETACH DELETE n")
43-
runner.run_cypher(f"CALL gds.graph.drop('{GRAPH_NAME}', false)")
41+
gds.run_cypher("MATCH (n) DETACH DELETE n")
42+
gds.graph.drop(GRAPH_NAME)
4443

4544

4645
@pytest.fixture

graphdatascience/tests/integration/test_error_handling.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import pytest
44

55
from graphdatascience import GraphDataScience
6-
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
76

87
GRAPH_NAME = "g"
98

109

1110
@pytest.fixture(autouse=True)
12-
def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
11+
def run_around_tests(gds: GraphDataScience) -> Generator[None, None, None]:
1312
# Runs before each test
14-
runner.run_cypher(
13+
gds.run_cypher(
1514
"""
1615
CREATE
1716
(a: Node),
@@ -26,8 +25,8 @@ def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
2625
yield # Test runs here
2726

2827
# Runs after each test
29-
runner.run_cypher("MATCH (n) DETACH DELETE n")
30-
runner.run_cypher(f"CALL gds.graph.drop('{GRAPH_NAME}', false)")
28+
gds.run_cypher("MATCH (n) DETACH DELETE n")
29+
gds.graph.drop(GRAPH_NAME)
3130

3231

3332
def test_bogus_algo(gds: GraphDataScience) -> None:

graphdatascience/tests/integration/test_graph_construct.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66

77
from graphdatascience.graph_data_science import GraphDataScience
88
from graphdatascience.query_runner.arrow_query_runner import ArrowQueryRunner
9-
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
109
from graphdatascience.server_version.server_version import ServerVersion
1110
from graphdatascience.tests.integration.conftest import AUTH, URI
1211

1312
GRAPH_NAME = "g"
1413

1514

1615
@pytest.fixture(autouse=True)
17-
def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
16+
def run_around_tests(gds: GraphDataScience) -> Generator[None, None, None]:
1817
# Runs before each test
19-
runner.run_cypher(
18+
gds.run_cypher(
2019
"""
2120
CREATE
2221
(a: Node {x: 1, y: 2, z: [42]}),
@@ -32,8 +31,8 @@ def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
3231
yield # Test runs here
3332

3433
# Runs after each test
35-
runner.run_cypher("MATCH (n) DETACH DELETE n")
36-
runner.run_cypher(f"CALL gds.graph.drop('{GRAPH_NAME}', false) YIELD graphName")
34+
gds.run_cypher("MATCH (n) DETACH DELETE n")
35+
gds.graph.drop(GRAPH_NAME)
3736

3837

3938
@pytest.mark.filterwarnings("ignore: GDS Enterprise users can use Apache Arrow")

graphdatascience/tests/integration/test_graph_ops.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from graphdatascience.graph_data_science import GraphDataScience
88
from graphdatascience.query_runner.arrow_query_runner import ArrowQueryRunner
9-
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
109
from graphdatascience.query_runner.query_runner import QueryRunner
1110
from graphdatascience.server_version.server_version import ServerVersion
1211
from graphdatascience.tests.integration.conftest import AUTH, DB, URI
@@ -15,9 +14,9 @@
1514

1615

1716
@pytest.fixture(autouse=True)
18-
def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
17+
def run_around_tests(gds: GraphDataScience) -> Generator[None, None, None]:
1918
# Runs before each test
20-
runner.run_cypher(
19+
gds.run_cypher(
2120
"""
2221
CREATE
2322
(a: Node {x: 1, y: 2, z: [42], name: "nodeA"}),
@@ -33,8 +32,8 @@ def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
3332
yield # Test runs here
3433

3534
# Runs after each test
36-
runner.run_cypher("MATCH (n) DETACH DELETE n")
37-
runner.run_cypher(f"CALL gds.graph.drop('{GRAPH_NAME}', false)")
35+
gds.run_cypher("MATCH (n) DETACH DELETE n")
36+
gds.graph.drop(GRAPH_NAME, failIfMissing=False)
3837

3938

4039
def test_project_graph_native(gds: GraphDataScience) -> None:
@@ -109,7 +108,7 @@ def test_beta_project_subgraph(runner: QueryRunner, gds: GraphDataScience) -> No
109108
result2 = gds.graph.list(sub_G)
110109
assert result2["nodeCount"][0] == 2
111110

112-
runner.run_cypher(f"CALL gds.graph.drop('{sub_G.name()}')")
111+
gds.graph.drop(sub_G)
113112

114113

115114
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 5, 0))
@@ -124,7 +123,7 @@ def test_project_subgraph(runner: QueryRunner, gds: GraphDataScience) -> None:
124123
result2 = gds.graph.list(sub_G)
125124
assert result2["nodeCount"][0] == 2
126125

127-
runner.run_cypher(f"CALL gds.graph.drop('{sub_G.name()}')")
126+
gds.graph.drop(sub_G)
128127

129128

130129
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 4, 0))
@@ -139,7 +138,7 @@ def test_sample_rwr(runner: QueryRunner, gds: GraphDataScience) -> None:
139138
result2 = gds.graph.list(rwr_G)
140139
assert result2["nodeCount"][0] == 2
141140

142-
runner.run_cypher(f"CALL gds.graph.drop('{rwr_G.name()}')")
141+
gds.graph.drop(rwr_G)
143142

144143

145144
@pytest.mark.skip_on_aura # The alpha procedure is not part of the allowlist
@@ -159,7 +158,7 @@ def test_sample_rwr_alpha(runner: QueryRunner, gds: GraphDataScience) -> None:
159158
result2 = gds.graph.list(rwr_G)
160159
assert result2["nodeCount"][0] == 2
161160

162-
runner.run_cypher(f"CALL gds.graph.drop('{rwr_G.name()}')")
161+
gds.graph.drop(rwr_G)
163162

164163

165164
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 4, 0))
@@ -174,7 +173,7 @@ def test_sample_cnarw(runner: QueryRunner, gds: GraphDataScience) -> None:
174173
result2 = gds.graph.list(cnarw_G)
175174
assert result2["nodeCount"][0] == 2
176175

177-
runner.run_cypher(f"CALL gds.graph.drop('{cnarw_G.name()}')")
176+
gds.graph.drop(cnarw_G)
178177

179178

180179
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 4, 0))
@@ -253,7 +252,7 @@ def test_graph_type_check(gds: GraphDataScience) -> None:
253252
"To resolve a graph name string into a `Graph` object, please use `gds.graph.get`"
254253
),
255254
):
256-
gds.graph.drop(G.name(), True) # type: ignore
255+
gds.graph.list(G.name()) # type: ignore
257256

258257
result = gds.graph.drop(G, True)
259258
assert result is not None

graphdatascience/tests/integration/test_simple_algo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010

1111
@fixture(autouse=True)
12-
def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
12+
def run_around_tests(gds: GraphDataScience) -> Generator[None, None, None]:
1313
# Runs before each test
14-
runner.run_cypher(
14+
gds.run_cypher(
1515
"""
1616
CREATE
1717
(a: Node),
@@ -26,11 +26,11 @@ def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
2626
yield # Test runs here
2727

2828
# Runs after each test
29-
runner.run_cypher("MATCH (n) DETACH DELETE n")
30-
runner.run_cypher(f"CALL gds.graph.drop('{GRAPH_NAME}')")
29+
gds.run_cypher("MATCH (n) DETACH DELETE n")
30+
gds.graph.drop(GRAPH_NAME)
3131

3232

33-
def test_pageRank_mutate(runner: Neo4jQueryRunner, gds: GraphDataScience) -> None:
33+
def test_pageRank_mutate(gds: GraphDataScience) -> None:
3434
G, _ = gds.graph.project(GRAPH_NAME, "*", "*")
3535

3636
result = gds.pageRank.mutate(G, mutateProperty="rank", dampingFactor=0.2, tolerance=0.3)

graphdatascience/tests/integration/test_single_mode_algos.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
from pytest import fixture
55

66
from graphdatascience.graph_data_science import GraphDataScience
7-
from graphdatascience.query_runner.neo4j_query_runner import Neo4jQueryRunner
87
from graphdatascience.server_version.server_version import ServerVersion
98

109
GRAPH_NAME = "g"
1110

1211

1312
@fixture(autouse=True)
14-
def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
13+
def run_around_tests(gds: GraphDataScience) -> Generator[None, None, None]:
1514
# Runs before each test
16-
runner.run_cypher(
15+
gds.run_cypher(
1716
"""
1817
CREATE
1918
(a: Node),
@@ -28,8 +27,8 @@ def run_around_tests(runner: Neo4jQueryRunner) -> Generator[None, None, None]:
2827
yield # Test runs here
2928

3029
# Runs after each test
31-
runner.run_cypher("MATCH (n) DETACH DELETE n")
32-
runner.run_cypher(f"CALL gds.graph.drop('{GRAPH_NAME}')")
30+
gds.run_cypher("MATCH (n) DETACH DELETE n")
31+
gds.graph.drop(GRAPH_NAME)
3332

3433

3534
@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 5, 0))

0 commit comments

Comments
 (0)