Skip to content

Commit e27b8e6

Browse files
committed
Merge branch 'black_syntax' into 'master'
reformat with black See merge request imi-sad/spikexplore!2
2 parents b798428 + 05d2ae6 commit e27b8e6

File tree

14 files changed

+403
-373
lines changed

14 files changed

+403
-373
lines changed

.github/workflows/black.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Lint
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: psf/black@stable
11+
with:
12+
options: "--check -l 150"
13+
src: "."
14+
version: "~= 22.0"
15+

.gitlab-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
image: python:3.9
22

33
stages:
4+
- format
45
- test
56

67
variables:
@@ -22,6 +23,11 @@ before_script:
2223
- pip install --upgrade -r requirements.txt
2324
- pip install black pytest
2425

26+
Formatting:
27+
stage: format
28+
script:
29+
- black --check -l 150 .
30+
2531
Tests:
2632
stage: test
2733
script:

setup.py

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
from setuptools import setup
22

33
setup(
4-
name='spikexplore',
5-
version='0.0.12',
6-
description='Graph exploration using inhomogeneous filtered diffusion',
7-
url='https://github.com/epfl-lts2/spikexplore',
8-
author='Nicolas Aspert, Benjamin Ricaud',
9-
10-
license='Apache license',
11-
packages=['spikexplore', 'spikexplore.backends'],
4+
name="spikexplore",
5+
version="0.0.12",
6+
description="Graph exploration using inhomogeneous filtered diffusion",
7+
url="https://github.com/epfl-lts2/spikexplore",
8+
author="Nicolas Aspert, Benjamin Ricaud",
9+
10+
license="Apache license",
11+
packages=["spikexplore", "spikexplore.backends"],
1212
scripts=[],
13-
install_requires=['pandas',
14-
'numpy',
15-
'networkx',
16-
'tqdm',
17-
'twython',
18-
'wikipedia-api',
19-
'python-louvain',
20-
'TwitterAPI'
21-
],
22-
python_requires='>=3.6',
13+
install_requires=["pandas", "numpy", "networkx", "tqdm", "twython", "wikipedia-api", "python-louvain", "TwitterAPI"],
14+
python_requires=">=3.6",
2315
classifiers=[
24-
'Development Status :: 4 - Beta',
25-
'Intended Audience :: Science/Research',
26-
'License :: OSI Approved :: Apache License',
27-
'Operating System :: POSIX :: Linux',
28-
'Programming Language :: Python :: 3.8',
29-
'Programming Language :: Python :: 3.7',
30-
'Programming Language :: Python :: 3.6'
16+
"Development Status :: 4 - Beta",
17+
"Intended Audience :: Science/Research",
18+
"License :: OSI Approved :: Apache License",
19+
"Operating System :: POSIX :: Linux",
20+
"Programming Language :: Python :: 3.8",
21+
"Programming Language :: Python :: 3.7",
22+
"Programming Language :: Python :: 3.6",
3123
],
3224
)

spikexplore/NodeInfo.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
21
class NodeInfo: # abstract interface
32
def update(self, new_info):
43
raise NotImplementedError
54

65
def get_nodes(self):
76
raise NotImplementedError
8-
9-
10-
11-
12-

spikexplore/backends/synthetic.py

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,76 @@
55

66

77
class SyntheticNetwork:
8-
class SynthNodeInfo(NodeInfo):
9-
def __init__(self, nodes=pd.DataFrame()):
10-
self.nodes = nodes
8+
class SynthNodeInfo(NodeInfo):
9+
def __init__(self, nodes=pd.DataFrame()):
10+
self.nodes = nodes
1111

12-
def update(self, new_info):
13-
return
12+
def update(self, new_info):
13+
return
1414

15-
def get_nodes(self):
16-
return self.nodes
15+
def get_nodes(self):
16+
return self.nodes
1717

18-
def __init__(self, g, config):
19-
# Instantiate an object
20-
self.G = g
21-
self.config = config
18+
def __init__(self, g, config):
19+
# Instantiate an object
20+
self.G = g
21+
self.config = config
2222

23-
def create_node_info(self):
24-
return self.SynthNodeInfo()
23+
def create_node_info(self):
24+
return self.SynthNodeInfo()
2525

26-
def get_neighbors(self, node_id):
27-
# collect info on the node and its (out going) edges
28-
# return 2 dataframes, one with edges info and the other with the node info
29-
G = self.G
30-
if node_id not in G:
31-
return self.SynthNodeInfo(pd.DataFrame()), pd.DataFrame()
32-
# node data
33-
node_df = pd.DataFrame([{'source': node_id, **G.nodes[node_id]}])
34-
# Edges and edge data
35-
if nx.is_directed(G):
36-
edges = G.out_edges(node_id, data=True)
37-
else:
38-
edges = G.edges(node_id, data=True)
26+
def get_neighbors(self, node_id):
27+
# collect info on the node and its (out going) edges
28+
# return 2 dataframes, one with edges info and the other with the node info
29+
G = self.G
30+
if node_id not in G:
31+
return self.SynthNodeInfo(pd.DataFrame()), pd.DataFrame()
32+
# node data
33+
node_df = pd.DataFrame([{"source": node_id, **G.nodes[node_id]}])
34+
# Edges and edge data
35+
if nx.is_directed(G):
36+
edges = G.out_edges(node_id, data=True)
37+
else:
38+
edges = G.edges(node_id, data=True)
3939

40-
edgeprop_dic_list = []
41-
for source, target, data in edges:
42-
edge_dic = {'source': source, 'target': target, **data}
43-
edgeprop_dic_list.append(edge_dic)
44-
edges_df = pd.DataFrame(edgeprop_dic_list)
45-
edges_df['weight'] = 1.0
46-
return self.SynthNodeInfo(node_df), edges_df
40+
edgeprop_dic_list = []
41+
for source, target, data in edges:
42+
edge_dic = {"source": source, "target": target, **data}
43+
edgeprop_dic_list.append(edge_dic)
44+
edges_df = pd.DataFrame(edgeprop_dic_list)
45+
edges_df["weight"] = 1.0
46+
return self.SynthNodeInfo(node_df), edges_df
4747

48-
def filter(self, node_info, edges_df):
49-
if len(edges_df) < self.config.min_degree:
50-
# discard the node
51-
node_info = self.SynthNodeInfo(pd.DataFrame())
52-
edges_df = pd.DataFrame()
53-
# filter the edges
54-
edges_df = self.filter_edges(edges_df)
55-
return node_info, edges_df
48+
def filter(self, node_info, edges_df):
49+
if len(edges_df) < self.config.min_degree:
50+
# discard the node
51+
node_info = self.SynthNodeInfo(pd.DataFrame())
52+
edges_df = pd.DataFrame()
53+
# filter the edges
54+
edges_df = self.filter_edges(edges_df)
55+
return node_info, edges_df
5656

57-
def filter_edges(self, edges_df):
58-
return edges_df
57+
def filter_edges(self, edges_df):
58+
return edges_df
5959

60-
def neighbors_list(self, edges_df):
61-
if edges_df.empty:
62-
return edges_df
63-
neighbors = edges_df['target'].unique().tolist()
64-
return neighbors
60+
def neighbors_list(self, edges_df):
61+
if edges_df.empty:
62+
return edges_df
63+
neighbors = edges_df["target"].unique().tolist()
64+
return neighbors
6565

66-
def neighbors_with_weights(self, edges_df):
67-
node_list = self.neighbors_list(edges_df)
68-
node_dic = {}
69-
for node in node_list:
70-
node_dic[node] = len(edges_df) # degree of the node
71-
return node_dic
66+
def neighbors_with_weights(self, edges_df):
67+
node_list = self.neighbors_list(edges_df)
68+
node_dic = {}
69+
for node in node_list:
70+
node_dic[node] = len(edges_df) # degree of the node
71+
return node_dic
7272

73-
def reshape_node_data(self, nodes_df):
74-
nodes_df.set_index('source', inplace=True)
75-
return nodes_df
73+
def reshape_node_data(self, nodes_df):
74+
nodes_df.set_index("source", inplace=True)
75+
return nodes_df
7676

77-
def add_graph_attributes(self, g, nodes_df, edges_df, nodes_info):
78-
g = add_edges_attributes(g, edges_df)
79-
g = add_node_attributes(g, self.reshape_node_data(nodes_df))
80-
return g
77+
def add_graph_attributes(self, g, nodes_df, edges_df, nodes_info):
78+
g = add_edges_attributes(g, edges_df)
79+
g = add_node_attributes(g, self.reshape_node_data(nodes_df))
80+
return g

0 commit comments

Comments
 (0)