Skip to content

Commit 4ea6f90

Browse files
authored
Format notebooks with ruff (#768)
* Format notebooks with ruff * Update nbconvert & fix title level * Print notebook diff * Bump dependencies to match CI * Format notebooks using pandoc 3.3.1 brew updated to 3.5 (and only has one version)
1 parent 83e5d02 commit 4ea6f90

24 files changed

+106
-67
lines changed

doc/modules/ROOT/pages/tutorials/centrality-algorithms.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ connection to the database.
3434

3535
[source, python, role=no-test]
3636
----
37-
from graphdatascience import GraphDataScience
38-
import pandas as pd
3937
import os
38+
39+
import pandas as pd
40+
41+
from graphdatascience import GraphDataScience
4042
----
4143

4244
[source, python, role=no-test]
@@ -101,8 +103,8 @@ gds.run_cypher(
101103
102104
gds.run_cypher(
103105
"""
104-
UNWIND $rels AS rel
105-
MATCH (source:City {node_id: rel.Origin}), (target:City {node_id: rel.Destination})
106+
UNWIND $rels AS rel
107+
MATCH (source:City {node_id: rel.Origin}), (target:City {node_id: rel.Destination})
106108
CREATE (source)-[:HAS_FLIGHT_TO]->(target)
107109
""",
108110
params={"rels": routes_df.to_dict("records")},

doc/modules/ROOT/pages/tutorials/community-detection.adoc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ connection to the database.
3434

3535
[source, python, role=no-test]
3636
----
37-
from graphdatascience import GraphDataScience
38-
import pandas as pd
3937
import os
38+
39+
import pandas as pd
40+
41+
from graphdatascience import GraphDataScience
4042
----
4143

4244
[source, python, role=no-test]
@@ -114,8 +116,8 @@ gds.run_cypher(
114116
115117
gds.run_cypher(
116118
"""
117-
UNWIND $rels AS rel
118-
MATCH (source:Subreddit {name: rel.SOURCE_SUBREDDIT}), (target:Subreddit {name: rel.TARGET_SUBREDDIT})
119+
UNWIND $rels AS rel
120+
MATCH (source:Subreddit {name: rel.SOURCE_SUBREDDIT}), (target:Subreddit {name: rel.TARGET_SUBREDDIT})
119121
CREATE (source)-[:HYPERLINKED_TO]->(target)
120122
""",
121123
params={"rels": relationship_df.to_dict("records")},
@@ -232,7 +234,7 @@ We can also check that the property was written by the below command.
232234
----
233235
gds.run_cypher(
234236
"""
235-
MATCH (n) WHERE 'louvainCommunityId' IN keys(n)
237+
MATCH (n) WHERE 'louvainCommunityId' IN keys(n)
236238
RETURN n.name, n.louvainCommunityId LIMIT 10
237239
"""
238240
)

doc/modules/ROOT/pages/tutorials/fastrp-and-knn.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ our GDS client connection to the database.
5555
[source, python, role=no-test]
5656
----
5757
import os
58+
5859
from graphdatascience import GraphDataScience
5960
6061
# Get Neo4j DB URI and credentials from environment if applicable

doc/modules/ROOT/pages/tutorials/gds-sessions-self-managed.adoc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ version `+1.12a1+` or later.
3434
[source, python, role=no-test]
3535
----
3636
from datetime import timedelta
37+
3738
%pip install "graphdatascience>=1.12a1"
3839
----
3940

@@ -50,7 +51,8 @@ is the main entry point for managing GDS Sessions.
5051
[source, python, role=no-test]
5152
----
5253
import os
53-
from graphdatascience.session import GdsSessions, AuraAPICredentials
54+
55+
from graphdatascience.session import AuraAPICredentials, GdsSessions
5456
5557
client_id = os.environ["AURA_API_CLIENT_ID"]
5658
client_secret = os.environ["AURA_API_CLIENT_SECRET"]
@@ -83,11 +85,13 @@ delete the session ourselves.
8385
[source, python, role=no-test]
8486
----
8587
import os
86-
from graphdatascience.session import DbmsConnectionInfo, AlgorithmCategory, CloudLocation
87-
from datetime import timedelta
88+
89+
from graphdatascience.session import AlgorithmCategory, CloudLocation, DbmsConnectionInfo
8890
8991
# Identify the Neo4j DBMS
90-
db_connection = DbmsConnectionInfo(uri=os.environ["NEO4J_URI"], username=os.environ["NEO4J_USER"], password=os.environ["NEO4J_PASSWORD"])
92+
db_connection = DbmsConnectionInfo(
93+
uri=os.environ["NEO4J_URI"], username=os.environ["NEO4J_USER"], password=os.environ["NEO4J_PASSWORD"]
94+
)
9195
# Specify where to create the GDS session
9296
cloud_location = CloudLocation(provider="gcp", region="europe-west1")
9397

doc/modules/ROOT/pages/tutorials/gds-sessions.adoc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ is the main entry point for managing GDS Sessions.
5050
[source, python, role=no-test]
5151
----
5252
import os
53-
from graphdatascience.session import GdsSessions, AuraAPICredentials
53+
54+
from graphdatascience.session import AuraAPICredentials, GdsSessions
5455
5556
client_id = os.environ["AURA_API_CLIENT_ID"]
5657
client_secret = os.environ["AURA_API_CLIENT_SECRET"]
@@ -84,10 +85,13 @@ delete the session ourselves.
8485
----
8586
import os
8687
from datetime import timedelta
87-
from graphdatascience.session import DbmsConnectionInfo, AlgorithmCategory
88+
89+
from graphdatascience.session import AlgorithmCategory, DbmsConnectionInfo
8890
8991
# Identify the AuraDB instance
90-
db_connection = DbmsConnectionInfo(uri=os.environ["AURA_DB_ADDRESS"], username=os.environ["AURA_DB_USER"], password=os.environ["AURA_DB_PW"])
92+
db_connection = DbmsConnectionInfo(
93+
uri=os.environ["AURA_DB_ADDRESS"], username=os.environ["AURA_DB_USER"], password=os.environ["AURA_DB_PW"]
94+
)
9195
# Create a GDS session!
9296
memory = sessions.estimate(
9397
node_count=20,

doc/modules/ROOT/pages/tutorials/heterogeneous-node-classification-with-hashgnn.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ connection to the database.
4444
----
4545
# Import our dependencies
4646
import os
47+
4748
from graphdatascience import GraphDataScience
4849
----
4950

doc/modules/ROOT/pages/tutorials/import-sample-export-gnn.adoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,16 @@ connection to the database.
5757
[source, python, role=no-test]
5858
----
5959
import os
60-
import pandas as pd
61-
from graphdatascience import GraphDataScience
60+
import random
61+
62+
import numpy as np
6263
import torch
63-
from torch_geometric.data import Data
6464
import torch.nn.functional as F
65+
from torch_geometric.data import Data
6566
from torch_geometric.nn import GCNConv
6667
from torch_geometric.transforms import RandomNodeSplit
67-
import random
68-
import numpy as np
68+
69+
from graphdatascience import GraphDataScience
6970
----
7071

7172
[source, python, role=no-test]

doc/modules/ROOT/pages/tutorials/kge-predict-transe-pyg-train.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ connection to the database.
4848

4949
[source, python, role=no-test]
5050
----
51+
import collections
5152
import os
52-
from graphdatascience import GraphDataScience
53+
54+
import pandas as pd
5355
import torch
5456
import torch.optim as optim
5557
from torch_geometric.data import Data, download_url
5658
from torch_geometric.nn import TransE
57-
import collections
5859
from tqdm import tqdm
59-
import pandas as pd
60+
61+
from graphdatascience import GraphDataScience
6062
----
6163

6264
[source, python, role=no-test]

doc/modules/ROOT/pages/tutorials/load-data-via-graph-construction.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ the `+graphdatascience+` package and import the client class.
3333
[source, python, role=no-test]
3434
----
3535
import os
36+
3637
from graphdatascience import GraphDataScience
3738
----
3839

doc/modules/ROOT/pages/tutorials/ml-pipelines-node-classification.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ install the `+graphdatascience+` package and import the client class.
3737
[source, python, role=no-test]
3838
----
3939
import os
40+
4041
from graphdatascience import GraphDataScience
4142
----
4243

examples/centrality-algorithms.ipynb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"\n",
3131
"This notebook will show how you can apply eigenvector centrality, betweenness centrality, degree centrality and closeness centrality on a graph dataset.\n",
3232
"\n",
33-
"### Setup\n",
33+
"## Setup\n",
3434
"\n",
3535
"We start by importing our dependencies and setting up our GDS client connection to the database."
3636
]
@@ -51,9 +51,11 @@
5151
"metadata": {},
5252
"outputs": [],
5353
"source": [
54-
"from graphdatascience import GraphDataScience\n",
54+
"import os\n",
55+
"\n",
5556
"import pandas as pd\n",
56-
"import os"
57+
"\n",
58+
"from graphdatascience import GraphDataScience"
5759
]
5860
},
5961
{
@@ -92,7 +94,7 @@
9294
"cell_type": "markdown",
9395
"metadata": {},
9496
"source": [
95-
"### Importing the dataset\n",
97+
"## Importing the dataset\n",
9698
"\n",
9799
"We import the dataset as a pandas dataframe first. We deal with two files here. The file `reachability-meta.csv.gz` stores the names of the cities and their information while the file `reachability.txt.gz` stores the edges of the graph. An edge exists from city `i` to city `j` if the estimated airline travel time is less than a threshold.\n"
98100
]
@@ -146,8 +148,8 @@
146148
"\n",
147149
"gds.run_cypher(\n",
148150
" \"\"\"\n",
149-
" UNWIND $rels AS rel \n",
150-
" MATCH (source:City {node_id: rel.Origin}), (target:City {node_id: rel.Destination}) \n",
151+
" UNWIND $rels AS rel\n",
152+
" MATCH (source:City {node_id: rel.Origin}), (target:City {node_id: rel.Destination})\n",
151153
" CREATE (source)-[:HAS_FLIGHT_TO]->(target)\n",
152154
" \"\"\",\n",
153155
" params={\"rels\": routes_df.to_dict(\"records\")},\n",
@@ -174,7 +176,7 @@
174176
"cell_type": "markdown",
175177
"metadata": {},
176178
"source": [
177-
"### Eigenvector Centrality\n",
179+
"## Eigenvector Centrality\n",
178180
"\n",
179181
"[Eigenvector centrality](https://neo4j.com/docs/graph-data-science/current/algorithms/eigenvector-centrality/) measures the importance or influence of a node based on its connections to other nodes in the network. A higher eigenvector centrality score suggests that a node is more central and influential within the network.\n",
180182
"\n",
@@ -289,7 +291,7 @@
289291
"cell_type": "markdown",
290292
"metadata": {},
291293
"source": [
292-
"### Betweenness Centrality\n",
294+
"## Betweenness Centrality\n",
293295
"\n",
294296
"[Betweenness Centrality](https://neo4j.com/docs/graph-data-science/current/algorithms/betweenness-centrality/) quantifies the importance of a node as a bridge or intermediary in the network. It measures how often a node lies on the shortest path between other pairs of nodes. \n",
295297
"\n",
@@ -367,7 +369,7 @@
367369
"cell_type": "markdown",
368370
"metadata": {},
369371
"source": [
370-
"### Degree Centrality\n",
372+
"## Degree Centrality\n",
371373
"\n",
372374
"[Degree Centrality](https://neo4j.com/docs/graph-data-science/current/algorithms/degree-centrality/) measures the number of connections (edges) a node has in the network. \n",
373375
"\n",
@@ -445,7 +447,7 @@
445447
"cell_type": "markdown",
446448
"metadata": {},
447449
"source": [
448-
"### Cleanup\n",
450+
"## Cleanup\n",
449451
"\n",
450452
"Before finishing we can clean up the example data from both the GDS in-memory state and the database."
451453
]
@@ -474,7 +476,7 @@
474476
"cell_type": "markdown",
475477
"metadata": {},
476478
"source": [
477-
"### References\n",
479+
"## References\n",
478480
"- For the network:\n",
479481
"Brendan J. Frey and Delbert Dueck. \"Clustering by passing messages between data points.\" Science 315.5814 (2007): 972-976.\n",
480482
"\n",

examples/community-detection.ipynb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"\n",
3434
"The tasks we cover here include performing initial graph preprocessing using Weakly Connected Components and then performing community detection on the largest component using the Louvain algorithm.\n",
3535
"\n",
36-
"### Setup\n",
36+
"## Setup\n",
3737
"\n",
3838
"We start by importing our dependencies and setting up our GDS client connection to the database."
3939
]
@@ -56,9 +56,11 @@
5656
"metadata": {},
5757
"outputs": [],
5858
"source": [
59-
"from graphdatascience import GraphDataScience\n",
59+
"import os\n",
60+
"\n",
6061
"import pandas as pd\n",
61-
"import os"
62+
"\n",
63+
"from graphdatascience import GraphDataScience"
6264
]
6365
},
6466
{
@@ -100,7 +102,7 @@
100102
"id": "48bd8af1",
101103
"metadata": {},
102104
"source": [
103-
"### Importing the dataset\n",
105+
"## Importing the dataset\n",
104106
"\n",
105107
"We import the dataset as a pandas dataframe first. We work with only a subset of the dataset. The sampled data is only till 1st March 2014. "
106108
]
@@ -187,8 +189,8 @@
187189
"\n",
188190
"gds.run_cypher(\n",
189191
" \"\"\"\n",
190-
" UNWIND $rels AS rel \n",
191-
" MATCH (source:Subreddit {name: rel.SOURCE_SUBREDDIT}), (target:Subreddit {name: rel.TARGET_SUBREDDIT}) \n",
192+
" UNWIND $rels AS rel\n",
193+
" MATCH (source:Subreddit {name: rel.SOURCE_SUBREDDIT}), (target:Subreddit {name: rel.TARGET_SUBREDDIT})\n",
192194
" CREATE (source)-[:HYPERLINKED_TO]->(target)\n",
193195
" \"\"\",\n",
194196
" params={\"rels\": relationship_df.to_dict(\"records\")},\n",
@@ -226,7 +228,7 @@
226228
"id": "9c259471",
227229
"metadata": {},
228230
"source": [
229-
"### Weakly Connected Components\n",
231+
"## Weakly Connected Components\n",
230232
"\n",
231233
"A graph dataset need not always be connected. That is, there may not exist a path from every node to \n",
232234
"every other node in the graph dataset (subgraphs in it may not be connected to each other at all). Hence, we \n",
@@ -332,7 +334,7 @@
332334
"id": "17942d04",
333335
"metadata": {},
334336
"source": [
335-
"### Community Detection using Louvain\n",
337+
"## Community Detection using Louvain\n",
336338
"\n",
337339
"We use the [Louvain](https://neo4j.com/docs/graph-data-science/current/algorithms/louvain/) algorithm to detect communities in our subgraph and assign a `louvainCommunityId` to each community."
338340
]
@@ -382,7 +384,7 @@
382384
"source": [
383385
"gds.run_cypher(\n",
384386
" \"\"\"\n",
385-
" MATCH (n) WHERE 'louvainCommunityId' IN keys(n) \n",
387+
" MATCH (n) WHERE 'louvainCommunityId' IN keys(n)\n",
386388
" RETURN n.name, n.louvainCommunityId LIMIT 10\n",
387389
" \"\"\"\n",
388390
")"
@@ -424,7 +426,7 @@
424426
"id": "5ed56f82",
425427
"metadata": {},
426428
"source": [
427-
"### Further ideas\n",
429+
"## Further ideas\n",
428430
"\n",
429431
"* Inspect the produced communities using [Bloom](https://neo4j.com/docs/bloom-user-guide/current/). You can use rule-based styling based on the community property.\n",
430432
"* Try to tune more parameters of Louvain and see how the communities differ.\n",
@@ -437,7 +439,7 @@
437439
"id": "6e00ed7b",
438440
"metadata": {},
439441
"source": [
440-
"### Cleanup\n",
442+
"## Cleanup\n",
441443
"\n",
442444
"Before finishing we can clean up the example data from both the GDS in-memory state and the database."
443445
]
@@ -471,7 +473,7 @@
471473
"id": "65dcb952",
472474
"metadata": {},
473475
"source": [
474-
"### References\n",
476+
"## References\n",
475477
"\n",
476478
"Srijan Kumar, William L. Hamilton, Jure Leskovec, and Dan Jurafsky. 2018. Community Interaction and Conflict on the Web. In Proceedings of the 2018 World Wide Web Conference (WWW '18). International World Wide Web Conferences Steering Committee, Republic and Canton of Geneva, CHE, 933–943. https://doi.org/10.1145/3178876.3186141"
477479
]

examples/fastrp-and-knn.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"outputs": [],
7878
"source": [
7979
"import os\n",
80+
"\n",
8081
"from graphdatascience import GraphDataScience\n",
8182
"\n",
8283
"# Get Neo4j DB URI and credentials from environment if applicable\n",

0 commit comments

Comments
 (0)