Skip to content

Commit 851fee1

Browse files
committed
Activate additional ruff rules
1 parent 507d635 commit 851fee1

16 files changed

+109
-37
lines changed

conftest.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Configure our testing suite."""
2+
3+
import networkx as nx
4+
import numpy as np
5+
import pytest
6+
import toponetx as tnx
7+
8+
9+
@pytest.fixture(autouse=True)
10+
def doctest_default_imports(doctest_namespace) -> None:
11+
"""Add default imports to the doctest namespace.
12+
13+
This fixture adds the following default imports to every doctest, so that their use
14+
is consistent across all doctests without boilerplate imports polluting the
15+
doctests themselves:
16+
17+
.. code-block:: python
18+
19+
import numpy as np
20+
import networkx as nx
21+
import toponetx as tnx
22+
23+
Parameters
24+
----------
25+
doctest_namespace : dict
26+
The namespace of the doctest.
27+
"""
28+
doctest_namespace["np"] = np
29+
doctest_namespace["nx"] = nx
30+
doctest_namespace["tnx"] = tnx

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# -- Project information -----------------------------------------------------
44

55
project = "TopoEmbedX"
6-
copyright = "2022-2023, PyT-Team, Inc."
6+
copyright = "2022-2023, PyT-Team, Inc." # noqa: A001
77
author = "PyT-Team Authors"
88
language = "en"
99

pyproject.toml

+31-2
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,49 @@ select = [
113113
"E", # code style
114114
"W", # warnings
115115
"I", # import order
116+
"D", # pydocstyle rules
116117
"UP", # pyupgrade rules
118+
"YTT", # flake8-2020 rules
119+
"S", # bandit rules
120+
"BLE", # blind except
117121
"B", # bugbear rules
122+
"A", # builtin shadowing
123+
"COM", # comma rules
124+
"C4", # comprehensions
125+
"DTZ", # datetime rules
126+
"T10", # debugger calls
127+
"FA", # future annotations
128+
"ISC", # implicit str concatenation
129+
"ICN", # import conventions
130+
"LOG", # logging rules
131+
"G", # logging format rules
118132
"PIE", # pie rules
119133
"Q", # quote rules
134+
"RSE", # raise rules
120135
"RET", # return rules
136+
"SLOT", # slot rules
121137
"SIM", # code simplifications
138+
"TID", # tidy imports
139+
"TC", # type checking rules
140+
"PTH", # use pathlib
141+
"PD", # pandas rules
142+
"PLC", # pylint conventions
143+
"PLE", # pylint errors
144+
"FLY", # flynt
122145
"NPY", # numpy rules
123146
"PERF", # performance rules
147+
"FURB", # refurb
124148
"RUF", # miscellaneous rules
125149
]
126-
ignore = ["E501"] # line too long
150+
ignore = [
151+
"E501", # line too long
152+
"COM812", # trailing commas; conflict with `ruff format`
153+
"ISC001", # implicitly single-line str concat; conflict with `ruff format`
154+
]
127155

128156
[tool.ruff.lint.per-file-ignores]
129-
"__init__.py" = ["F401", "F403"]
157+
"__init__.py" = ["F403"]
158+
"test/**.py" = ["S101"]
130159

131160
[tool.ruff.lint.pydocstyle]
132161
convention = "numpy"

test/test_neighborhood.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ def test_neighborhood_from_complex_matrix_dimension_cell_complex(self):
2929
cc2 = tnx.classes.CellComplex([[0, 1, 2], [1, 2, 3]])
3030

3131
ind, A = tex.neighborhood.neighborhood_from_complex(cc1)
32-
assert A.todense().shape == tuple([9, 9])
32+
assert A.todense().shape == (9, 9)
3333
assert len(ind) == 9
3434

3535
ind, A = tex.neighborhood.neighborhood_from_complex(cc2)
36-
assert A.todense().shape == tuple([4, 4])
36+
assert A.todense().shape == (4, 4)
3737
assert len(ind) == 4
3838

3939
ind, A = tex.neighborhood.neighborhood_from_complex(
4040
cc1, neighborhood_type="coadj"
4141
)
42-
assert A.todense().shape == tuple([9, 9])
42+
assert A.todense().shape == (9, 9)
4343
assert len(ind) == 9
4444

4545
ind, A = tex.neighborhood.neighborhood_from_complex(
4646
cc2, neighborhood_type="coadj"
4747
)
48-
assert A.todense().shape == tuple([4, 4])
48+
assert A.todense().shape == (4, 4)
4949
assert len(ind) == 4

test/test_tutorials.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
"""Unit tests for the tutorials."""
22

3-
import glob
43
import subprocess
54
import tempfile
5+
from pathlib import Path
66

77
import pytest
88

99

1010
def _exec_tutorial(path):
11+
"""Execute the notebooks for testing in the given directory.
12+
13+
Parameters
14+
----------
15+
path : str
16+
Path to the tutorials directory.
17+
"""
1118
with tempfile.NamedTemporaryFile(suffix=".ipynb") as tmp_file:
1219
args = [
1320
"jupyter",
@@ -21,14 +28,20 @@ def _exec_tutorial(path):
2128
tmp_file.name,
2229
path,
2330
]
24-
subprocess.check_call(args)
31+
subprocess.check_call(args) # noqa: S603
2532

2633

2734
TUTORIALS_DIR = "tutorials"
28-
paths = sorted(glob.glob(f"{TUTORIALS_DIR}/*.ipynb"))
35+
paths = sorted(Path(TUTORIALS_DIR).glob("*.ipynb"))
2936

3037

3138
@pytest.mark.parametrize("path", paths)
3239
def test_tutorial(path):
33-
"""Test the tutorials."""
40+
"""Test the tutorials.
41+
42+
Parameters
43+
----------
44+
path : str
45+
Path to the tutorials directory.
46+
"""
3447
_exec_tutorial(path)

topoembedx/__init__.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
"""Initialize the library with modules and other content."""
22

3-
from .classes.cell2vec import Cell2Vec
4-
from .classes.cell_diff2vec import CellDiff2Vec
5-
from .classes.deepcell import DeepCell
6-
from .classes.higher_order_laplacian_eigenmaps import HigherOrderLaplacianEigenmaps
7-
from .classes.hoglee import HOGLEE
8-
from .classes.hope import HOPE
3+
from .classes import *

topoembedx/classes/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
"""Initialize the classes module of TopoEmbedX."""
2+
3+
from .cell2vec import *
4+
from .cell_diff2vec import *
5+
from .deepcell import *
6+
from .higher_order_laplacian_eigenmaps import *
7+
from .hoglee import *
8+
from .hope import *
9+
from .random_walks import *

topoembedx/classes/cell2vec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def fit(
111111
neighborhood_type : {"adj", "coadj"}, default="adj"
112112
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
113113
neighborhood_dim : dict
114-
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
114+
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
115115
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
116116
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
117117
neighborhood_dim["rank"].

topoembedx/classes/cell_diff2vec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def fit(
9191
neighborhood_type : {"adj", "coadj"}, default="adj"
9292
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
9393
neighborhood_dim : dict
94-
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
94+
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
9595
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
9696
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
9797
neighborhood_dim["rank"].

topoembedx/classes/deepcell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def fit(
9191
neighborhood_type : {"adj", "coadj"}, default="adj"
9292
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
9393
neighborhood_dim : dict
94-
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
94+
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
9595
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
9696
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
9797
neighborhood_dim["rank"].

topoembedx/classes/higher_order_laplacian_eigenmaps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def fit(
5656
neighborhood_type : {"adj", "coadj"}, default="adj"
5757
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
5858
neighborhood_dim : dict
59-
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
59+
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
6060
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
6161
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
6262
neighborhood_dim["rank"].

topoembedx/classes/hoglee.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def fit(
4848
neighborhood_type : {"adj", "coadj"}, default="adj"
4949
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
5050
neighborhood_dim : dict
51-
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
51+
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
5252
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
5353
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
5454
neighborhood_dim["rank"].

topoembedx/classes/hope.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ def fit(
146146
147147
Examples
148148
--------
149-
>>> import toponetx as tnx
150149
>>> from topoembedx import HOPE
151-
>>> ccc = tnx.classes.CombinatorialComplex()
150+
>>> ccc = tnx.CombinatorialComplex()
152151
>>> ccc.add_cell([2, 5], rank=1)
153152
>>> ccc.add_cell([2, 4], rank=1)
154153
>>> ccc.add_cell([7, 8], rank=1)

topoembedx/classes/random_walks.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ def transition_from_adjacency(
4343
This function generates a transition matrix from an adjacency matrix
4444
using the following steps:
4545
46-
1. Add self-loop to the adjaency matrix if self_loop is set to True
47-
2. Compute the degree matrix
46+
1. Add self-loop to the adjacency matrix if ``self_loop`` is set to ``True``.
47+
2. Compute the degree matrix.
4848
3. Compute the transition matrix by taking the dot product of the inverse of
49-
the degree matrix and the adjacency matrix
49+
the degree matrix and the adjacency matrix.
5050
5151
Parameters
5252
----------
@@ -55,7 +55,7 @@ def transition_from_adjacency(
5555
sub_sampling : float, default=0.1
5656
The rate of subsampling.
5757
self_loop : bool, default=True
58-
A flag indicating whether to add self-loop to the adjacency matrix.
58+
Whether to add self-loops to the adjacency matrix.
5959
6060
Returns
6161
-------
@@ -64,7 +64,6 @@ def transition_from_adjacency(
6464
6565
Examples
6666
--------
67-
>>> import numpy as np
6867
>>> A = np.array([[0, 1, 1, 0], [1, 0, 1, 0], [1, 1, 0, 1], [0, 0, 1, 0]])
6968
>>> transition_from_adjacency(A)
7069
array([[0.33333333, 0.33333333, 0.33333333, 0. ],
@@ -165,7 +164,6 @@ def random_walk(
165164
166165
Examples
167166
--------
168-
>>> import numpy as np
169167
>>> transition_matrix = np.array(
170168
... [
171169
... [0.0, 1.0, 0.0, 0.0],
@@ -175,10 +173,9 @@ def random_walk(
175173
... ]
176174
... )
177175
>>> states = ["A", "B", "C", "D"]
178-
>>> walks = random_walk(
176+
>>> random_walk(
179177
... length=3, num_walks=2, states=states, transition_matrix=transition_matrix
180178
... )
181-
>>> print(walks)
182179
[['B', 'C', 'D'], ['B', 'C', 'B']]
183180
"""
184181
rw = RandomWalk(states, transition_matrix)

topoembedx/exceptions.py renamed to topoembedx/exception.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
"""Base classes for TopoEmbedX exceptions."""
1+
"""Base errors and exceptions for TopoEmbedX."""
2+
3+
__all__ = ["TopoEmbedXError", "TopoEmbedXException", "TopoEmbedXNotImplementedError"]
24

35

46
class TopoEmbedXException(Exception):

topoembedx/neighborhood.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ def neighborhood_from_complex(
1313
) -> tuple[list, csr_matrix]:
1414
"""Compute the neighborhood of a complex.
1515
16-
This function returns the indices and matrix for the neighborhood specified
17-
by `neighborhood_type`
18-
and `neighborhood_dim` for the input complex `domain`.
16+
This function returns the indices and matrix for the neighborhood specified by
17+
`neighborhood_type` and `neighborhood_dim` for the input complex `domain`.
1918
2019
Parameters
2120
----------
@@ -24,7 +23,7 @@ def neighborhood_from_complex(
2423
neighborhood_type : {"adj", "coadj"}, default="adj"
2524
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
2625
neighborhood_dim : dict
27-
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
26+
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
2827
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
2928
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
3029
neighborhood_dim["rank"].

0 commit comments

Comments
 (0)