Skip to content
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

Format code in docstrings with Ruff #2790

Merged
merged 1 commit into from
Dec 20, 2023
Merged
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
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
2 changes: 1 addition & 1 deletion scanpy/external/pp/_hashsolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions scanpy/neighbors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions scanpy/plotting/_baseplot_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
Loading