Skip to content

Activate additional ruff rules #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Configure our testing suite."""

import networkx as nx
import numpy as np
import pytest
import toponetx as tnx


@pytest.fixture(autouse=True)
def doctest_default_imports(doctest_namespace) -> None:
"""Add default imports to the doctest namespace.

This fixture adds the following default imports to every doctest, so that their use
is consistent across all doctests without boilerplate imports polluting the
doctests themselves:

.. code-block:: python

import numpy as np
import networkx as nx
import toponetx as tnx

Parameters
----------
doctest_namespace : dict
The namespace of the doctest.
"""
doctest_namespace["np"] = np
doctest_namespace["nx"] = nx
doctest_namespace["tnx"] = tnx
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# -- Project information -----------------------------------------------------

project = "TopoEmbedX"
copyright = "2022-2023, PyT-Team, Inc."
copyright = "2022-2023, PyT-Team, Inc." # noqa: A001
author = "PyT-Team Authors"
language = "en"

Expand Down
33 changes: 31 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,49 @@ select = [
"E", # code style
"W", # warnings
"I", # import order
"D", # pydocstyle rules
"UP", # pyupgrade rules
"YTT", # flake8-2020 rules
"S", # bandit rules
"BLE", # blind except
"B", # bugbear rules
"A", # builtin shadowing
"COM", # comma rules
"C4", # comprehensions
"DTZ", # datetime rules
"T10", # debugger calls
"FA", # future annotations
"ISC", # implicit str concatenation
"ICN", # import conventions
"LOG", # logging rules
"G", # logging format rules
"PIE", # pie rules
"Q", # quote rules
"RSE", # raise rules
"RET", # return rules
"SLOT", # slot rules
"SIM", # code simplifications
"TID", # tidy imports
"TC", # type checking rules
"PTH", # use pathlib
"PD", # pandas rules
"PLC", # pylint conventions
"PLE", # pylint errors
"FLY", # flynt
"NPY", # numpy rules
"PERF", # performance rules
"FURB", # refurb
"RUF", # miscellaneous rules
]
ignore = ["E501"] # line too long
ignore = [
"E501", # line too long
"COM812", # trailing commas; conflict with `ruff format`
"ISC001", # implicitly single-line str concat; conflict with `ruff format`
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "F403"]
"__init__.py" = ["F403"]
"test/**.py" = ["S101"]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
Expand Down
8 changes: 4 additions & 4 deletions test/test_neighborhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ def test_neighborhood_from_complex_matrix_dimension_cell_complex(self):
cc2 = tnx.classes.CellComplex([[0, 1, 2], [1, 2, 3]])

ind, A = tex.neighborhood.neighborhood_from_complex(cc1)
assert A.todense().shape == tuple([9, 9])
assert A.todense().shape == (9, 9)
assert len(ind) == 9

ind, A = tex.neighborhood.neighborhood_from_complex(cc2)
assert A.todense().shape == tuple([4, 4])
assert A.todense().shape == (4, 4)
assert len(ind) == 4

ind, A = tex.neighborhood.neighborhood_from_complex(
cc1, neighborhood_type="coadj"
)
assert A.todense().shape == tuple([9, 9])
assert A.todense().shape == (9, 9)
assert len(ind) == 9

ind, A = tex.neighborhood.neighborhood_from_complex(
cc2, neighborhood_type="coadj"
)
assert A.todense().shape == tuple([4, 4])
assert A.todense().shape == (4, 4)
assert len(ind) == 4
21 changes: 17 additions & 4 deletions test/test_tutorials.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
"""Unit tests for the tutorials."""

import glob
import subprocess
import tempfile
from pathlib import Path

import pytest


def _exec_tutorial(path):
"""Execute the notebooks for testing in the given directory.

Parameters
----------
path : str
Path to the tutorials directory.
"""
with tempfile.NamedTemporaryFile(suffix=".ipynb") as tmp_file:
args = [
"jupyter",
Expand All @@ -21,14 +28,20 @@ def _exec_tutorial(path):
tmp_file.name,
path,
]
subprocess.check_call(args)
subprocess.check_call(args) # noqa: S603


TUTORIALS_DIR = "tutorials"
paths = sorted(glob.glob(f"{TUTORIALS_DIR}/*.ipynb"))
paths = sorted(Path(TUTORIALS_DIR).glob("*.ipynb"))


@pytest.mark.parametrize("path", paths)
def test_tutorial(path):
"""Test the tutorials."""
"""Test the tutorials.

Parameters
----------
path : str
Path to the tutorials directory.
"""
_exec_tutorial(path)
7 changes: 1 addition & 6 deletions topoembedx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
"""Initialize the library with modules and other content."""

from .classes.cell2vec import Cell2Vec
from .classes.cell_diff2vec import CellDiff2Vec
from .classes.deepcell import DeepCell
from .classes.higher_order_laplacian_eigenmaps import HigherOrderLaplacianEigenmaps
from .classes.hoglee import HOGLEE
from .classes.hope import HOPE
from .classes import *
8 changes: 8 additions & 0 deletions topoembedx/classes/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
"""Initialize the classes module of TopoEmbedX."""

from .cell2vec import *
from .cell_diff2vec import *
from .deepcell import *
from .higher_order_laplacian_eigenmaps import *
from .hoglee import *
from .hope import *
from .random_walks import *
8 changes: 4 additions & 4 deletions topoembedx/classes/cell2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ def __init__(

def fit(
self,
complex: tnx.Complex,
domain: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim=None,
) -> None:
"""Fit a Cell2Vec model.

Parameters
----------
complex : toponetx.classes.Complex
domain : toponetx.classes.Complex
A complex object. The complex object can be one of the following:
- CellComplex
- CombinatorialComplex
Expand All @@ -111,7 +111,7 @@ def fit(
neighborhood_type : {"adj", "coadj"}, default="adj"
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
neighborhood_dim : dict
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
neighborhood_dim["rank"].
Expand All @@ -128,7 +128,7 @@ def fit(
colored hypergraph.
"""
self.ind, self.A = neighborhood_from_complex(
complex, neighborhood_type, neighborhood_dim
domain, neighborhood_type, neighborhood_dim
)

g = nx.from_numpy_array(self.A)
Expand Down
8 changes: 4 additions & 4 deletions topoembedx/classes/cell_diff2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def __init__(

def fit(
self,
complex: tnx.Complex,
domain: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim=None,
) -> None:
"""Fit a CellDiff2Vec model.

Parameters
----------
complex : toponetx.classes.Complex
domain : toponetx.classes.Complex
A complex object. The complex object can be one of the following:
- CellComplex
- CombinatorialComplex
Expand All @@ -91,7 +91,7 @@ def fit(
neighborhood_type : {"adj", "coadj"}, default="adj"
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
neighborhood_dim : dict
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
neighborhood_dim["rank"].
Expand All @@ -108,7 +108,7 @@ def fit(
colored hypergraph.
"""
self.ind, self.A = neighborhood_from_complex(
complex, neighborhood_type, neighborhood_dim
domain, neighborhood_type, neighborhood_dim
)

self.A.setdiag(1)
Expand Down
8 changes: 4 additions & 4 deletions topoembedx/classes/deepcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def __init__(

def fit(
self,
complex: tnx.Complex,
domain: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim=None,
) -> None:
"""Fit the model.

Parameters
----------
complex : toponetx.classes.Complex
domain : toponetx.classes.Complex
A complex object. The complex object can be one of the following:
- CellComplex
- CombinatorialComplex
Expand All @@ -91,7 +91,7 @@ def fit(
neighborhood_type : {"adj", "coadj"}, default="adj"
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
neighborhood_dim : dict
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
neighborhood_dim["rank"].
Expand All @@ -108,7 +108,7 @@ def fit(
colored hypergraph.
"""
self.ind, self.A = neighborhood_from_complex(
complex, neighborhood_type, neighborhood_dim
domain, neighborhood_type, neighborhood_dim
)

self.A.setdiag(1)
Expand Down
8 changes: 4 additions & 4 deletions topoembedx/classes/higher_order_laplacian_eigenmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def __init__(

def fit(
self,
complex: tnx.Complex,
domain: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim=None,
) -> None:
"""Fit a Higher Order Laplacian Eigenmaps model.

Parameters
----------
complex : toponetx.classes.Complex
domain : toponetx.classes.Complex
A complex object. The complex object can be one of the following:
- CellComplex
- CombinatorialComplex
Expand All @@ -56,7 +56,7 @@ def fit(
neighborhood_type : {"adj", "coadj"}, default="adj"
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
neighborhood_dim : dict
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
neighborhood_dim["rank"].
Expand All @@ -73,7 +73,7 @@ def fit(
colored hypergraph.
"""
self.ind, self.A = neighborhood_from_complex(
complex, neighborhood_type, neighborhood_dim
domain, neighborhood_type, neighborhood_dim
)

self.A.setdiag(1)
Expand Down
8 changes: 4 additions & 4 deletions topoembedx/classes/hoglee.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def __init__(self, dimensions: int = 128, seed: int = 42):

def fit(
self,
complex: tnx.Complex,
domain: tnx.Complex,
neighborhood_type: Literal["adj", "coadj"] = "adj",
neighborhood_dim=None,
) -> None:
"""Fit a Higher Order Geometric Laplacian EigenMaps model.

Parameters
----------
complex : toponetx.classes.Complex
domain : toponetx.classes.Complex
A complex object. The complex object can be one of the following:
- CellComplex
- CombinatorialComplex
Expand All @@ -48,7 +48,7 @@ def fit(
neighborhood_type : {"adj", "coadj"}, default="adj"
The type of neighborhood to compute. "adj" for adjacency matrix, "coadj" for coadjacency matrix.
neighborhood_dim : dict
The integer parmaters needed to specify the neighborhood of the cells to generate the embedding.
The integer parameters needed to specify the neighborhood of the cells to generate the embedding.
In TopoNetX (co)adjacency neighborhood matrices are specified via one or two parameters.
- For Cell/Simplicial/Path complexes (co)adjacency matrix is specified by a single parameter, this is precisely
neighborhood_dim["rank"].
Expand All @@ -65,7 +65,7 @@ def fit(
colored hypergraph.
"""
self.ind, self.A = neighborhood_from_complex(
complex, neighborhood_type, neighborhood_dim
domain, neighborhood_type, neighborhood_dim
)

self.A.setdiag(1)
Expand Down
Loading
Loading