From 79759342b97b630f8d482b10bd3bebf4c43d496f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 16:31:18 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.15.6 → v0.16.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.15.6...v0.16.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f91485..6525805 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,7 +33,7 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.15.6 + rev: v0.16.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From c3466aa1d7d1bc956d364ced9a00cfbac93ee666 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 16:33:07 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.py | 2 +- src/mopsy/__init__.py | 4 ++-- src/mopsy/adders.py | 10 ++++------ src/mopsy/checkutils.py | 3 +-- src/mopsy/helpers.py | 22 +++++++++++----------- src/mopsy/mops.py | 15 ++++++++------- src/mopsy/nops.py | 4 ++-- src/mopsy/sops.py | 15 ++++++++------- src/mopsy/utils.py | 4 +--- 9 files changed, 38 insertions(+), 41 deletions(-) diff --git a/setup.py b/setup.py index 4c4d8f3..c2a3ec4 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ if __name__ == "__main__": try: setup(use_scm_version={"version_scheme": "no-guess-dev"}) - except: # noqa + except: print( "\n\nAn error occurred while building the project, " "please ensure you have the most updated version of setuptools, " diff --git a/src/mopsy/__init__.py b/src/mopsy/__init__.py index dabba4e..d9caf9c 100644 --- a/src/mopsy/__init__.py +++ b/src/mopsy/__init__.py @@ -21,5 +21,5 @@ finally: del version, PackageNotFoundError -from .helpers import * # noqa: F403 -from .adders import * # noqa: F403 +from .adders import * +from .helpers import * diff --git a/src/mopsy/adders.py b/src/mopsy/adders.py index 789c92a..2e8f54d 100644 --- a/src/mopsy/adders.py +++ b/src/mopsy/adders.py @@ -1,5 +1,3 @@ -from typing import Union - import numpy as np import scipy as sp @@ -11,7 +9,7 @@ __license__ = "MIT" -def append_row(mat: sp.sparse.spmatrix, row: Union[sp.sparse.spmatrix, np.ndarray]) -> sp.sparse.spmatrix: +def append_row(mat: sp.sparse.spmatrix, row: sp.sparse.spmatrix | np.ndarray) -> sp.sparse.spmatrix: """A generic append function for sparse matrices. Args: @@ -30,7 +28,7 @@ def append_row(mat: sp.sparse.spmatrix, row: Union[sp.sparse.spmatrix, np.ndarra return sparse_append(mat=mat, row_or_column=row, axis=0) -def append_col(mat: sp.sparse.spmatrix, col: Union[sp.sparse.spmatrix, np.ndarray]) -> sp.sparse.spmatrix: +def append_col(mat: sp.sparse.spmatrix, col: sp.sparse.spmatrix | np.ndarray) -> sp.sparse.spmatrix: """A generic append function for sparse matrices. Args: @@ -52,8 +50,8 @@ def append_col(mat: sp.sparse.spmatrix, col: Union[sp.sparse.spmatrix, np.ndarra def sparse_append( mat: sp.sparse.spmatrix, - row_or_column: Union[sp.sparse.spmatrix, np.ndarray], - axis: Union[int, bool], + row_or_column: sp.sparse.spmatrix | np.ndarray, + axis: int | bool, ) -> sp.sparse.spmatrix: """A generic append function for sparse matrices. diff --git a/src/mopsy/checkutils.py b/src/mopsy/checkutils.py index 0135438..0d82301 100644 --- a/src/mopsy/checkutils.py +++ b/src/mopsy/checkutils.py @@ -1,13 +1,12 @@ # this file only exists because of circular imports error -from typing import Union __author__ = "jkanche" __copyright__ = "jkanche" __license__ = "MIT" -def check_axis(axis: Union[int, bool]): +def check_axis(axis: int | bool): """Check if axis has a correct value. Args: diff --git a/src/mopsy/helpers.py b/src/mopsy/helpers.py index 57e2293..aa344e5 100644 --- a/src/mopsy/helpers.py +++ b/src/mopsy/helpers.py @@ -1,5 +1,5 @@ +from collections.abc import Callable, Sequence from statistics import mean, median -from typing import Callable, Sequence, Union import numpy import scipy @@ -13,7 +13,7 @@ def colsum( - mat: Union[numpy.ndarray, scipy.sparse.spmatrix], + mat: numpy.ndarray | scipy.sparse.spmatrix, group: Sequence = None, non_zero: bool = False, ) -> numpy.ndarray: @@ -39,7 +39,7 @@ def colsum( def rowsum( - mat: Union[numpy.ndarray, scipy.sparse.spmatrix], + mat: numpy.ndarray | scipy.sparse.spmatrix, group: Sequence = None, non_zero: bool = False, ) -> numpy.ndarray: @@ -64,7 +64,7 @@ def rowsum( def colmean( - mat: Union[numpy.ndarray, scipy.sparse.spmatrix], + mat: numpy.ndarray | scipy.sparse.spmatrix, group: Sequence = None, non_zero: bool = False, ) -> numpy.ndarray: @@ -89,7 +89,7 @@ def colmean( def rowmean( - mat: Union[numpy.ndarray, scipy.sparse.spmatrix], + mat: numpy.ndarray | scipy.sparse.spmatrix, group: Sequence = None, non_zero: bool = False, ) -> numpy.ndarray: @@ -114,7 +114,7 @@ def rowmean( def colmedian( - mat: Union[numpy.ndarray, scipy.sparse.spmatrix], + mat: numpy.ndarray | scipy.sparse.spmatrix, group: Sequence = None, non_zero: bool = False, ) -> numpy.ndarray: @@ -139,7 +139,7 @@ def colmedian( def rowmedian( - mat: Union[numpy.ndarray, scipy.sparse.spmatrix], + mat: numpy.ndarray | scipy.sparse.spmatrix, group: Sequence = None, non_zero: bool = False, ) -> numpy.ndarray: @@ -165,8 +165,8 @@ def rowmedian( def apply( func: Callable, - mat: Union[numpy.ndarray, scipy.sparse.spmatrix], - axis: Union[int, bool], + mat: numpy.ndarray | scipy.sparse.spmatrix, + axis: int | bool, group: Sequence = None, non_zero: bool = False, ): @@ -201,8 +201,8 @@ def apply( def multi_apply( funcs: Sequence[Callable], - mat: Union[numpy.ndarray, scipy.sparse.spmatrix], - axis: Union[int, bool], + mat: numpy.ndarray | scipy.sparse.spmatrix, + axis: int | bool, group: Sequence = None, non_zero: bool = False, ): diff --git a/src/mopsy/mops.py b/src/mopsy/mops.py index ca6fed8..ea7ca57 100644 --- a/src/mopsy/mops.py +++ b/src/mopsy/mops.py @@ -1,5 +1,6 @@ +from collections.abc import Callable, Sequence from itertools import groupby -from typing import Any, Callable, Optional, Sequence, Tuple, Union +from typing import Any import numpy as np @@ -41,7 +42,7 @@ def groupby_indices(self, group: Sequence) -> dict: """ return {k: [x[0] for x in v] for k, v in groupby(sorted(enumerate(group), key=lambda x: x[1]), lambda x: x[1])} - def _apply(self, func: Callable[[list], Any], axis: Union[int, bool]): + def _apply(self, func: Callable[[list], Any], axis: int | bool): if self.non_zero: def funcwrapper(mat): @@ -56,8 +57,8 @@ def apply( self, func: Callable[[list], Any], group: Sequence = None, - axis: Union[int, bool] = 0, - ) -> Tuple[np.ndarray, Optional[Sequence]]: + axis: int | bool = 0, + ) -> tuple[np.ndarray, Sequence | None]: """Apply a function to groups along an axis. Args: @@ -93,7 +94,7 @@ def apply( rgroups.append(kcat) result = np.stack(result, axis=axis) except Exception as e: - raise Exception(f"Error: applying function: {str(e)}") + raise Exception(f"Error: applying function: {e!s}") return result, rgroups @@ -102,7 +103,7 @@ def multi_apply( funcs: Sequence[Callable[[list], Any]], group: list = None, axis: int = 0, - ) -> Tuple[np.ndarray, Optional[Sequence]]: + ) -> tuple[np.ndarray, Sequence | None]: """Apply multiple functions, the first axis of the ndarray specifies the results of the inputs functions in the same order. @@ -145,6 +146,6 @@ def multi_apply( result = nmats except Exception as e: - raise Exception(f"Error: applying function: {str(e)}") + raise Exception(f"Error: applying function: {e!s}") return result, rgroups diff --git a/src/mopsy/nops.py b/src/mopsy/nops.py index e4ff325..923d3f0 100644 --- a/src/mopsy/nops.py +++ b/src/mopsy/nops.py @@ -1,4 +1,4 @@ -from typing import Iterator, Sequence, Tuple, Union +from collections.abc import Iterator, Sequence import numpy as np @@ -15,7 +15,7 @@ class Nops(Mops): def __init__(self, mat: np.ndarray, non_zero: bool = False) -> None: super().__init__(mat, non_zero=non_zero) - def iter(self, group: Sequence[str] = None, axis: Union[int, bool] = 0) -> Iterator[Tuple]: + def iter(self, group: Sequence[str] = None, axis: int | bool = 0) -> Iterator[tuple]: """Iterator over groups and an axis. Args: diff --git a/src/mopsy/sops.py b/src/mopsy/sops.py index 9eb69ca..67d4c9a 100644 --- a/src/mopsy/sops.py +++ b/src/mopsy/sops.py @@ -1,5 +1,6 @@ +from collections.abc import Callable, Iterator, Sequence from statistics import mean -from typing import Any, Callable, Iterator, Optional, Sequence, Tuple, Union +from typing import Any import numpy as np from scipy import sparse as sp @@ -28,7 +29,7 @@ def __init__(self, mat: sp.spmatrix, non_zero: bool = False) -> None: """ super().__init__(mat, non_zero=non_zero) - def iter(self, group: list = None, axis: Union[int, bool] = 0) -> Iterator[Tuple]: + def iter(self, group: list = None, axis: int | bool = 0) -> Iterator[tuple]: """Iterator over groups and an axis. Args: @@ -58,7 +59,7 @@ def iter(self, group: list = None, axis: Union[int, bool] = 0) -> Iterator[Tuple else: yield (k, Sops(mat[:, v], self.non_zero)) - def _apply(self, func: Callable[[list], Any], axis: Union[int, bool] = 0) -> np.ndarray: + def _apply(self, func: Callable[[list], Any], axis: int | bool = 0) -> np.ndarray: mat = self.matrix.tocsc() if axis == 0 else self.matrix.tocsr() if self.non_zero: # reduction along an axis @@ -95,8 +96,8 @@ def apply( self, func: Callable[[list], Any], group: Sequence = None, - axis: Union[int, bool] = 0, - ) -> Tuple[np.ndarray, Optional[Sequence]]: + axis: int | bool = 0, + ) -> tuple[np.ndarray, Sequence | None]: """Apply a function to groups along an axis. Args: @@ -129,8 +130,8 @@ def multi_apply( self, funcs: Sequence[Callable[[list], Any]], group: list = None, - axis: Union[int, bool] = 0, - ) -> Tuple[np.ndarray, Optional[Sequence]]: + axis: int | bool = 0, + ) -> tuple[np.ndarray, Sequence | None]: """Apply multiple functions, the first axis of the ndarray specifies the results of the inputs functions in the same order. diff --git a/src/mopsy/utils.py b/src/mopsy/utils.py index e800ab0..53658d8 100644 --- a/src/mopsy/utils.py +++ b/src/mopsy/utils.py @@ -1,5 +1,3 @@ -from typing import Union - import numpy as np import scipy.sparse as sp @@ -11,7 +9,7 @@ __license__ = "MIT" -def get_matrix_type(mat: Union[np.ndarray, sp.spmatrix], non_zero: bool = False): +def get_matrix_type(mat: np.ndarray | sp.spmatrix, non_zero: bool = False): """Get an internal matrix state. Args: