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

add flake8 pre-commit #1689

Merged
merged 87 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
40dc2c3
add flake8 pre-commit
Zethson Feb 24, 2021
55737d9
fix pre-commit
Zethson Feb 24, 2021
f653e5a
add E402 to flake8 ignore
Zethson Feb 24, 2021
daf03c9
revert neighbors
Zethson Feb 24, 2021
9a53065
Merge branch 'master' into feature/flake8
Zethson Feb 24, 2021
2b79a88
fix flake8
Zethson Feb 24, 2021
617168f
address review
Zethson Feb 25, 2021
ae43e3d
fix comment character in .flake8
Zethson Feb 25, 2021
7db4e60
fix test
Zethson Feb 25, 2021
48f0648
black
Zethson Feb 25, 2021
e742c66
review round 2
Zethson Feb 25, 2021
a5b1290
review round 3
Zethson Feb 25, 2021
718a06c
readded double comments
Zethson Feb 25, 2021
2a0a19d
Ignoring E262 & reverted comment
Zethson Feb 25, 2021
ebb2b01
using self for obs_tidy
Zethson Feb 25, 2021
d2bb2a9
Restore setup.py
flying-sheep Mar 1, 2021
ecc47a2
rm call of black test (#1690)
Koncopd Feb 24, 2021
f338863
Fix print_versions for python<3.8 (#1691)
ivirshup Feb 25, 2021
ce68cd1
add codecov so we can have a badge to point to (#1693)
ivirshup Feb 25, 2021
b5cc4b6
Attempt server-side search (#1672)
ivirshup Feb 25, 2021
8b0d8f0
Fix paga_path (#1047)
flying-sheep Mar 1, 2021
24d1b2e
Switch to flit
flying-sheep Dec 3, 2020
364f320
add setup.py while leaving it ignored
flying-sheep Jan 15, 2021
8f4f87e
Update install instructions
flying-sheep Jan 14, 2021
d4f7d4c
Circumvent new pip check (see pypa/pip#9628)
flying-sheep Feb 11, 2021
3db4814
Go back to regular pip (#1702)
flying-sheep Mar 2, 2021
6a97d73
codecov comment (#1704)
ivirshup Mar 2, 2021
47af631
Use joblib for parallelism in regress_out (#1695)
ivirshup Mar 3, 2021
6d36c6b
Add sparsificiation step before sparse-dependent Scrublet calls (#1707)
pinin4fjords Mar 3, 2021
c7bd6dc
Fix version on Travis (#1713)
flying-sheep Mar 3, 2021
4eb64c2
`sc.metrics` module (add confusion matrix & Geary's C methods) (#915)
ivirshup Mar 4, 2021
c11c486
Fix clipped images in docs (#1717)
ivirshup Mar 4, 2021
f637c08
Cleanup normalize_total (#1667)
ivirshup Mar 5, 2021
1e814cb
deprecate scvi (#1703)
mjayasur Mar 9, 2021
056d183
updated ecosystem.rst to add triku (#1722)
alexmascension Mar 9, 2021
ade2975
Minor addition to contributing docs (#1726)
ivirshup Mar 10, 2021
5f7f01f
Preserve category order when groupby is a list (#1735)
gokceneraslan Mar 11, 2021
b90e730
Asymmetrical diverging colormaps and vcenter (#1551)
gokceneraslan Mar 14, 2021
8fe2897
add flake8 pre-commit
Zethson Feb 24, 2021
5a144a3
add E402 to flake8 ignore
Zethson Feb 24, 2021
55aee90
revert neighbors
Zethson Feb 24, 2021
fc9d2b6
address review
Zethson Feb 25, 2021
893a034
black
Zethson Feb 25, 2021
53948bd
using self for obs_tidy
Zethson Feb 25, 2021
95958ff
rebased
Zethson Mar 15, 2021
99e1218
rebasing
Zethson Mar 15, 2021
e030ab1
rebasing
Zethson Mar 15, 2021
38e5624
rebasing
Zethson Mar 15, 2021
9bd1f0f
Merge branch 'master' into feature/flake8
Zethson Mar 15, 2021
7529cd3
add flake8 to dev docs
Zethson Mar 15, 2021
c7b9ee4
add autopep8 to pre-commits
Zethson Mar 15, 2021
ad38870
add flake8 ignore docs
Zethson Mar 15, 2021
c968244
add exception todos
Zethson Mar 15, 2021
83e31cf
add ignore directories
Zethson Mar 15, 2021
f8b6b70
reinstated lambdas
Zethson Mar 15, 2021
9e6722a
fix tests
Zethson Mar 15, 2021
207f650
fix tests
Zethson Mar 15, 2021
7fa610e
fix tests
Zethson Mar 15, 2021
976d825
fix tests
Zethson Mar 15, 2021
e3d916c
fix tests
Zethson Mar 15, 2021
5ca8527
Add E741 to allowed flake8 violations.
Zethson Mar 16, 2021
c8b7273
Add F811 flake8 ignore for tests
Zethson Mar 16, 2021
9abc967
Fix mask comparison
Zethson Mar 16, 2021
3a83228
Fix mask comparison
Zethson Mar 16, 2021
e2a4ce7
fix flake8 config file
Zethson Mar 16, 2021
0c69d81
readded autopep8
Zethson Mar 16, 2021
d89105f
import Literal
Zethson Mar 16, 2021
5cdfa9d
revert literal import
Zethson Mar 16, 2021
da412fc
fix scatterplot pca import
Zethson Mar 16, 2021
220ac15
false comparison & unused vars
Zethson Mar 16, 2021
f373a70
Add cleaner level determination
Zethson Mar 16, 2021
5adcfae
Fix comment formatting
Zethson Mar 16, 2021
ce2fb44
Add smoother dev documentation
Zethson Mar 16, 2021
8d7e6e4
fix flake8
Zethson Mar 16, 2021
64f6d7a
Readd long comment
Zethson Mar 16, 2021
32dcf96
Assuming X as array like
Zethson Mar 16, 2021
07cab3d
fix flake8
Zethson Mar 16, 2021
699aaac
fix flake8 config
Zethson Mar 16, 2021
79619ce
reverted rank_genes
Zethson Mar 16, 2021
99a8f2e
fix disp_mean_bin formatting
Zethson Mar 16, 2021
abe0846
fix formatting
Zethson Mar 16, 2021
16a0394
add final todos
Zethson Mar 16, 2021
46f4ca7
boolean checks with is
Zethson Mar 17, 2021
ad418d8
_dpt formatting
Zethson Mar 17, 2021
10e5d76
literal fixes
Zethson Mar 17, 2021
9b1da8c
links to leafs
Zethson Mar 17, 2021
c372f0b
revert paga variable naming
ivirshup Mar 18, 2021
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
37 changes: 37 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Can't yet be moved to the pyproject.toml due to https://gitlab.com/pycqa/flake8/-/issues/428#note_251982786
[flake8]
max-line-length = 88
ignore = # module imported but unused -> required for Scanpys API
F401,
# line break before a binary operator -> black does not adhere to PEP8
W503,
# line break occured after a binary operator -> black does not adhere to PEP8
W504,
# line too long -> we accept long comment lines; black gets rid of long code lines
E501,
# whitespace before : -> black does not adhere to PEP8
E203,
# missing whitespace after ,', ';', or ':' -> black does not adhere to PEP8
E231,
# module level import not at top of file -> required to circumvent circular imports for Scanpys API
E402,
# continuation line over-indented for hanging indent -> black does not adhere to PEP8
E126,
# E266 too many leading '#' for block comment -> Scanpy allows them for comments into sections
E262,
# inline comment should start with '# ' -> Scanpy allows them for specific explanations
E266,
# Do not assign a lambda expression, use a def -> Scanpy allows lambda expression assignments,
E731,
# allow I, O, l as variable names -> I is the identity matrix, i, j, k, l is reasonable indexing notation
E741
per-file-ignores =
# F811 Redefinition of unused name from line, does not play nice with pytest fixtures
tests/test*.py: F811
exclude =
.git,
__pycache__,
build,
docs/_build,
dist,

9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ repos:
rev: 20.8b1
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.5
hooks:
- id: autopep8
args: ["-i"]
7 changes: 6 additions & 1 deletion docs/dev/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Code style

New code should follow
`Black <https://black.readthedocs.io/en/stable/the_black_code_style.html>`__
and Scanpy’s
and
`flake8 <https://flake8.pycqa.org>`__.
We ignore a couple of flake8 checks which are documented in the .flake8 file in the root of this repository.
To learn how to ignore checks per line please read
`flake8 violations <https://flake8.pycqa.org/en/latest/user/violations.html>`__.
Additionally, we use Scanpy’s
`EditorConfig <https://github.com/theislab/scanpy/blob/master/.editorconfig>`__,
so using an editor/IDE with support for both is helpful.
6 changes: 4 additions & 2 deletions scanpy/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def get_igraph_from_adjacency(adjacency, directed=None):
g.add_edges(list(zip(sources, targets)))
try:
g.es['weight'] = weights
except:
except KeyError:
pass
if g.vcount() != adjacency.shape[0]:
logg.warning(
Expand Down Expand Up @@ -554,7 +554,9 @@ def warn_with_traceback(message, category, filename, lineno, file=None, line=Non
import traceback

traceback.print_stack()
log = file if hasattr(file, 'write') else sys.stderr
log = ( # noqa: F841 # TODO Does this need fixing?
file if hasattr(file, 'write') else sys.stderr
)
settings.write(warnings.formatwarning(message, category, filename, lineno, line))


Expand Down
14 changes: 7 additions & 7 deletions scanpy/external/pl.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,15 @@ def scrublet_score_distribution(
figsize: Optional[Tuple[float, float]] = (8, 3),
):
"""\
Plot histogram of doublet scores for observed transcriptomes and simulated doublets.
Plot histogram of doublet scores for observed transcriptomes and simulated doublets.

The histogram for simulated doublets is useful for determining the correct doublet
score threshold.

The histogram for simulated doublets is useful for determining the correct doublet
score threshold.

Parameters
----------
adata
An annData object resulting from func:`~scanpy.external.scrublet`.
An annData object resulting from func:`~scanpy.external.scrublet`.
scale_hist_obs
Set y axis scale transformation in matplotlib for the plot of observed
transcriptomes (e.g. "linear", "log", "symlog", "logit")
Expand All @@ -353,9 +353,9 @@ def scrublet_score_distribution(
See also
--------
:func:`~scanpy.external.pp.scrublet`: Main way of running Scrublet, runs
preprocessing, doublet simulation (this function) and calling.
preprocessing, doublet simulation (this function) and calling.
:func:`~scanpy.external.pp.scrublet_simulate_doublets`: Run Scrublet's doublet
simulation separately for advanced usage.
simulation separately for advanced usage.
"""

threshold = adata.uns['scrublet']['threshold']
Expand Down
62 changes: 31 additions & 31 deletions scanpy/external/pp/_scrublet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from anndata import AnnData
from typing import Collection, Tuple, Optional, Union
from typing import Optional
import numpy as np
from scipy import sparse

Expand Down Expand Up @@ -40,7 +40,7 @@ def scrublet(
and directly call functions of Scrublet(). You may also undertake your own
preprocessing, simulate doublets with
scanpy.external.pp.scrublet_simulate_doublets(), and run the core scrublet
function scanpy.external.pp.scrublet.scrublet().
function scanpy.external.pp.scrublet.scrublet().

.. note::
More information and bug reports `here
Expand All @@ -61,7 +61,7 @@ def scrublet(
as adata. This should have been built from adata_obs after
filtering genes and cells and selcting highly-variable genes.
sim_doublet_ratio
Number of doublets to simulate relative to the number of observed
Number of doublets to simulate relative to the number of observed
transcriptomes.
expected_doublet_rate
Where adata_sim not suplied, the estimated doublet rate for the
Expand All @@ -73,8 +73,8 @@ def scrublet(
synthetic doublets. If 1.0, each doublet is created by simply adding
the UMI counts from two randomly sampled observed transcriptomes. For
values less than 1, the UMI counts are added and then randomly sampled
at the specified rate.
knn_dist_metric
at the specified rate.
knn_dist_metric
Distance metric used when finding nearest neighbors. For list of
valid values, see the documentation for annoy (if `use_approx_neighbors`
is True) or sklearn.neighbors.NearestNeighbors (if `use_approx_neighbors`
Expand All @@ -90,16 +90,16 @@ def scrublet(
If True, center the data such that each gene has a mean of 0.
`sklearn.decomposition.PCA` will be used for dimensionality
reduction.
n_prin_comps
n_prin_comps
Number of principal components used to embed the transcriptomes prior
to k-nearest-neighbor graph construction.
to k-nearest-neighbor graph construction.
use_approx_neighbors
Use approximate nearest neighbor method (annoy) for the KNN
Use approximate nearest neighbor method (annoy) for the KNN
classifier.
get_doublet_neighbor_parents
If True, return (in .uns) the parent transcriptomes that generated the
doublet neighbors of each observed transcriptome. This information can
be used to infer the cell states that generated a given doublet state.
be used to infer the cell states that generated a given doublet state.
n_neighbors
Number of neighbors used to construct the KNN graph of observed
transcriptomes and simulated doublets. If ``None``, this is
Expand Down Expand Up @@ -133,7 +133,7 @@ def scrublet(
``adata.uns['scrublet']['doublet_scores_sim']``
Doublet scores for each simulated doublet transcriptome

``adata.uns['scrublet']['doublet_parents']``
``adata.uns['scrublet']['doublet_parents']``
Pairs of ``.obs_names`` used to generate each simulated doublet
transcriptome

Expand All @@ -143,9 +143,9 @@ def scrublet(
See also
--------
:func:`~scanpy.external.pp.scrublet_simulate_doublets`: Run Scrublet's doublet
simulation separately for advanced usage.
simulation separately for advanced usage.
:func:`~scanpy.external.pl.scrublet_score_distribution`: Plot histogram of doublet
scores for observed transcriptomes and simulated doublets.
scores for observed transcriptomes and simulated doublets.
"""
try:
import scrublet as sl
Expand Down Expand Up @@ -185,7 +185,7 @@ def scrublet(
pp.highly_variable_genes(adata_obs, subset=True)
else:
logged = pp.log1p(adata_obs, copy=True)
hvg = pp.highly_variable_genes(logged)
_ = pp.highly_variable_genes(logged)
adata_obs = adata_obs[:, logged.var['highly_variable']]

# Simulate the doublets based on the raw expressions from the normalised
Expand Down Expand Up @@ -257,7 +257,7 @@ def _scrublet_call_doublets(
transcriptomes and simulated doublets. This is a wrapper around the core
functions of `Scrublet <https://github.com/swolock/scrublet>`__ to allow
for flexibility in applying Scanpy filtering operations upstream. Unless
you know what you're doing you should use the main scrublet() function.
you know what you're doing you should use the main scrublet() function.

.. note::
More information and bug reports `here
Expand Down Expand Up @@ -293,20 +293,20 @@ def _scrublet_call_doublets(
reduction, unless `mean_center` is True.
n_prin_comps
Number of principal components used to embed the transcriptomes prior
to k-nearest-neighbor graph construction.
to k-nearest-neighbor graph construction.
use_approx_neighbors
Use approximate nearest neighbor method (annoy) for the KNN
Use approximate nearest neighbor method (annoy) for the KNN
classifier.
knn_dist_metric
Distance metric used when finding nearest neighbors. For list of
valid values, see the documentation for annoy (if `use_approx_neighbors`
is True) or sklearn.neighbors.NearestNeighbors (if `use_approx_neighbors`
is False).
get_doublet_neighbor_parents
If True, return the parent transcriptomes that generated the
doublet neighbors of each observed transcriptome. This information can
be used to infer the cell states that generated a given
doublet state.
If True, return the parent transcriptomes that generated the
doublet neighbors of each observed transcriptome. This information can
be used to infer the cell states that generated a given
doublet state.
threshold
Doublet score threshold for calling a transcriptome a doublet. If
`None`, this is set automatically by looking for the minimum between
Expand All @@ -316,7 +316,7 @@ def _scrublet_call_doublets(
predicted doublets in a 2-D embedding.
random_state
Initial state for doublet simulation and nearest neighbors.
verbose
verbose
If True, print progress updates.

Returns
Expand All @@ -333,7 +333,7 @@ def _scrublet_call_doublets(
``adata.uns['scrublet']['doublet_scores_sim']``
Doublet scores for each simulated doublet transcriptome

``adata.uns['scrublet']['doublet_parents']``
``adata.uns['scrublet']['doublet_parents']``
Pairs of ``.obs_names`` used to generate each simulated doublet transcriptome

``uns['scrublet']['parameters']``
Expand Down Expand Up @@ -453,16 +453,16 @@ def scrublet_simulate_doublets(
The annotated data matrix of shape ``n_obs`` × ``n_vars``. Rows
correspond to cells and columns to genes. Genes should have been
filtered for expression and variability, and the object should contain
raw expression of the same dimensions.
raw expression of the same dimensions.
layer
Layer of adata where raw values are stored, or 'X' if values are in .X.
Layer of adata where raw values are stored, or 'X' if values are in .X.
sim_doublet_ratio
Number of doublets to simulate relative to the number of observed
Number of doublets to simulate relative to the number of observed
transcriptomes. If `None`, self.sim_doublet_ratio is used.
synthetic_doublet_umi_subsampling
Rate for sampling UMIs when creating synthetic doublets. If 1.0,
each doublet is created by simply adding the UMIs from two randomly
sampled observed transcriptomes. For values less than 1, the
Rate for sampling UMIs when creating synthetic doublets. If 1.0,
each doublet is created by simply adding the UMIs from two randomly
sampled observed transcriptomes. For values less than 1, the
UMI counts are added and then randomly sampled at the specified
rate.

Expand All @@ -471,7 +471,7 @@ def scrublet_simulate_doublets(
adata : anndata.AnnData with simulated doublets in .X
if ``copy=True`` it returns or else adds fields to ``adata``:

``adata.uns['scrublet']['doublet_parents']``
``adata.uns['scrublet']['doublet_parents']``
Pairs of ``.obs_names`` used to generate each simulated doublet transcriptome

``uns['scrublet']['parameters']``
Expand All @@ -480,9 +480,9 @@ def scrublet_simulate_doublets(
See also
--------
:func:`~scanpy.external.pp.scrublet`: Main way of running Scrublet, runs
preprocessing, doublet simulation (this function) and calling.
preprocessing, doublet simulation (this function) and calling.
:func:`~scanpy.external.pl.scrublet_score_distribution`: Plot histogram of doublet
scores for observed transcriptomes and simulated doublets.
scores for observed transcriptomes and simulated doublets.
"""
try:
import scrublet as sl
Expand Down
2 changes: 1 addition & 1 deletion scanpy/external/tl/_trimap.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def trimap(

Example
-------

>>> import scanpy as sc
>>> import scanpy.external as sce
>>> pbmc = sc.datasets.pbmc68k_reduced()
Expand Down
5 changes: 2 additions & 3 deletions scanpy/get/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from scipy.sparse import spmatrix

from anndata import AnnData
import warnings

# --------------------------------------------------------------------------------
# Plotting data helpers
Expand Down Expand Up @@ -96,7 +95,7 @@ def rank_genes_groups_df(
def _check_indices(
dim_df: pd.DataFrame,
alt_index: pd.Index,
dim: "Literal['obs', 'var']",
dim: "Literal['obs', 'var']", # noqa: F821 # TODO Does this need fixing?
keys: List[str],
alias_index: Optional[pd.Index] = None,
use_raw: bool = False,
Expand Down Expand Up @@ -176,7 +175,7 @@ def _get_array_values(
X,
dim_names: pd.Index,
keys: List[str],
axis: "Literal[0, 1]",
axis: "Literal[0, 1]", # noqa: F821 # TODO Does this need fixing?
backed: bool,
):
# TODO: This should be made easier on the anndata side
Expand Down
Loading