diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 791dbb2235..6a3b5dd53d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,11 +3,14 @@ repos: rev: v0.1.8 hooks: - id: ruff + types_or: [python, pyi, jupyter] args: ["--fix"] - id: ruff-format + types_or: [python, pyi, jupyter] # The following can be removed once PLR0917 is out of preview - name: ruff preview rules id: ruff + types_or: [python, pyi, jupyter] args: ["--preview", "--select=PLR0917"] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 diff --git a/pyproject.toml b/pyproject.toml index ba0999437a..70aa675655 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -194,7 +194,10 @@ exclude_also = [ "if TYPE_CHECKING:", ] -[tool.ruff] +[tool.ruff.format] +docstring-code-format = true + +[tool.ruff.lint] select = [ "E", # Error detected by Pycodestyle "F", # Errors detected by Pyflakes @@ -217,13 +220,13 @@ ignore = [ # allow I, O, l as variable names -> I is the identity matrix, i, j, k, l is reasonable indexing notation "E741", ] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] # Do not assign a lambda expression, use a def "scanpy/tools/_rank_genes_groups.py" = ["E731"] -[tool.ruff.isort] +[tool.ruff.lint.isort] known-first-party = ["scanpy"] required-imports = ["from __future__ import annotations"] -[tool.ruff.flake8-tidy-imports.banned-api] +[tool.ruff.lint.flake8-tidy-imports.banned-api] "pytest.importorskip".msg = "Use the “@needs” decorator/mark instead" "pandas.api.types.is_categorical_dtype".msg = "Use isinstance(s.dtype, CategoricalDtype) instead" "pandas.value_counts".msg = "Use pd.Series(a).value_counts() instead" diff --git a/scanpy/external/pp/_hashsolo.py b/scanpy/external/pp/_hashsolo.py index 9d18206448..9d24c269bd 100644 --- a/scanpy/external/pp/_hashsolo.py +++ b/scanpy/external/pp/_hashsolo.py @@ -332,7 +332,7 @@ def hashsolo( >>> import anndata >>> import scanpy.external as sce >>> adata = anndata.read_h5ad("data.h5ad") - >>> sce.pp.hashsolo(adata, ['Hash1', 'Hash2', 'Hash3']) + >>> sce.pp.hashsolo(adata, ["Hash1", "Hash2", "Hash3"]) >>> adata.obs.head() """ print( diff --git a/scanpy/neighbors/__init__.py b/scanpy/neighbors/__init__.py index 65595f0b87..474c8b5ad1 100644 --- a/scanpy/neighbors/__init__.py +++ b/scanpy/neighbors/__init__.py @@ -440,7 +440,7 @@ def transitions(self) -> np.ndarray | csr_matrix: Is conjugate to the symmetrized transition matrix via:: - self.transitions = self.Z * self.transitions_sym / self.Z + self.transitions = self.Z * self.transitions_sym / self.Z where ``self.Z`` is the diagonal matrix storing the normalization of the underlying kernel matrix. @@ -461,7 +461,7 @@ def transitions_sym(self) -> np.ndarray | csr_matrix | None: Is conjugate to the transition matrix via:: - self.transitions_sym = self.Z / self.transitions * self.Z + self.transitions_sym = self.Z / self.transitions * self.Z where ``self.Z`` is the diagonal matrix storing the normalization of the underlying kernel matrix. diff --git a/scanpy/plotting/_baseplot_class.py b/scanpy/plotting/_baseplot_class.py index a3cc34e5fa..38e83c0e67 100644 --- a/scanpy/plotting/_baseplot_class.py +++ b/scanpy/plotting/_baseplot_class.py @@ -814,8 +814,8 @@ def show(self, return_axes: bool | None = None): ------- >>> import scanpy as sc >>> adata = sc.datasets.pbmc68k_reduced() - >>> markers = ['C1QA', 'PSAP', 'CD79A', 'CD79B', 'CST3', 'LYZ'] - >>> sc.pl._baseplot_class.BasePlot(adata, markers, groupby='bulk_labels').show() + >>> markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"] + >>> sc.pl._baseplot_class.BasePlot(adata, markers, groupby="bulk_labels").show() """ self.make_figure() @@ -848,8 +848,10 @@ def savefig(self, filename: str, bbox_inches: str | None = "tight", **kwargs): ------- >>> import scanpy as sc >>> adata = sc.datasets.pbmc68k_reduced() - >>> markers = ['C1QA', 'PSAP', 'CD79A', 'CD79B', 'CST3', 'LYZ'] - >>> sc.pl._baseplot_class.BasePlot(adata, markers, groupby='bulk_labels').savefig('plot.pdf') + >>> markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"] + >>> sc.pl._baseplot_class.BasePlot(adata, markers, groupby="bulk_labels").savefig( + ... "plot.pdf" + ... ) """ self.make_figure() plt.savefig(filename, bbox_inches=bbox_inches, **kwargs)