Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 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
43 changes: 30 additions & 13 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
# Can't yet be moved to the pyproject.toml due to https://gitlab.com/pycqa/flake8/-/issues/428#note_251982786
[flake8]
Comment thread
Zethson marked this conversation as resolved.
max-line-length = 88
Comment thread
Zethson marked this conversation as resolved.
# switched off since they conflict with black's standards
ignore = F401, # module imported but unused -> required for Scanpys API
W503, # line break before a binary operator -> black does not adhere to PEP8
W504, # line break occured after a binary operator -> black does not adhere to PEP8
E501, # line too long -> we accept long comment lines; black gets rid of long code lines
E203, # whitespace before : -> black does not adhere to PEP8
E231, # missing whitespace after ,', ';', or ':' -> black does not adhere to PEP8
E402, # module level import not at top of file -> required to circumvent circular imports for Scanpys API
E126, # continuation line over-indented for hanging indent -> black does not adhere to PEP8
E266, # E266 too many leading '#' for block comment -> Scanpy allows them for comments into sections
E731 # Do not assign a lambda expression, use a def -> Scanpy allows lambda expression assignments
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
docs/_build,
dist,

5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ repos:
rev: 3.8.4
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.5
hooks:
- id: autopep8
args: ["-i"]
5 changes: 2 additions & 3 deletions docs/dev/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ Code style
----------

New code should follow
`Black <https://black.readthedocs.io/en/stable/the_black_code_style.html>`__,
`Black <https://black.readthedocs.io/en/stable/the_black_code_style.html>`__
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.
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
Expand Down
4 changes: 3 additions & 1 deletion scanpy/_utils.py
Original file line number Diff line number Diff line change
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 # noqa: F841
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
3 changes: 2 additions & 1 deletion scanpy/external/pl.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ def scrublet_score_distribution(
"""\
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
----------
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
Comment thread
Zethson marked this conversation as resolved.
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']", # noqa: F821
dim: "Literal['obs', 'var']", # noqa: F821 # TODO Does this need fixing?
Comment thread
Zethson marked this conversation as resolved.
Outdated
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]", # noqa: F821
axis: "Literal[0, 1]", # noqa: F821 # TODO Does this need fixing?
Comment thread
Zethson marked this conversation as resolved.
Outdated
backed: bool,
):
# TODO: This should be made easier on the anndata side
Expand Down
14 changes: 7 additions & 7 deletions scanpy/neighbors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ def _compute_connectivities_diffmap(self, density_normalize=True):
# make the weight matrix sparse
if not self.knn:
mask = W > 1e-14
W[mask == False] = 0 # noqa: E712
W[~mask] = 0
else:
# restrict number of neighbors to ~k
# build a symmetric mask
Expand All @@ -872,7 +872,7 @@ def _compute_connectivities_diffmap(self, density_normalize=True):
W[j, i] = W[i, j]
mask[j, i] = True
# set all entries that are not nearest neighbors to zero
W[mask == False] = 0 # noqa: E712
W[~mask] = 0
else:
W = (
Dsq.copy()
Expand Down Expand Up @@ -1023,14 +1023,14 @@ def _get_dpt_row(self, i):
mask = self._connected_components[1] == label
row = sum(
(
self.eigen_values[k]
/ (1 - self.eigen_values[k])
* (self.eigen_basis[i, k] - self.eigen_basis[:, k])
self.eigen_values[j]
/ (1 - self.eigen_values[j])
* (self.eigen_basis[i, j] - self.eigen_basis[:, j])
)
** 2
# account for float32 precision
for k in range(0, self.eigen_values.size)
if self.eigen_values[k] < 0.9994
for j in range(0, self.eigen_values.size)
if self.eigen_values[j] < 0.9994
)
# thanks to Marius Lange for pointing Alex to this:
# we will likely remove the contributions from the stationary state below when making
Expand Down
7 changes: 4 additions & 3 deletions scanpy/plotting/_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def pca_overview(adata: AnnData, **params):
show = params['show'] if 'show' in params else None
if 'show' in params:
del params['show']
scatterplots.pca(adata, **params, show=False) # noqa: F821
pca(adata, **params, show=False)
pca_loadings(adata, show=False)
pca_variance_ratio(adata, show=show)

Expand Down Expand Up @@ -165,6 +165,7 @@ def dpt_timeseries(
):
"""\
Heatmap of pseudotime series.

Parameters
----------
as_heatmap
Expand Down Expand Up @@ -364,7 +365,7 @@ def _fig_show_save_or_axes(plot_obj, return_fig, show, save):
plot_obj.make_figure()
savefig_or_show(plot_obj.DEFAULT_SAVE_PREFIX, show=show, save=save)
show = settings.autoshow if show is None else show
if not show:
if show == False: # noqa: E712 # TODO Does this need fixing? -> is False
Comment thread
Zethson marked this conversation as resolved.
Outdated
return plot_obj.get_axes()


Expand Down Expand Up @@ -966,7 +967,7 @@ def rank_genes_groups_violin(
)
savefig_or_show(writekey, show=show, save=save)
axs.append(_ax)
if not show:
if show == False: # noqa: E712 TODO Does this need fixing?
Comment thread
Zethson marked this conversation as resolved.
Outdated
return axs


Expand Down
2 changes: 1 addition & 1 deletion scanpy/plotting/_tools/paga.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def paga_compare(
if suptitle is not None:
pl.suptitle(suptitle)
_utils.savefig_or_show('paga_compare', show=show, save=save)
if not show:
if show == False: # noqa: E712 # TODO Does this need fixing?
Comment thread
Zethson marked this conversation as resolved.
Outdated
return axs


Expand Down
10 changes: 5 additions & 5 deletions scanpy/plotting/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,9 @@ def setup_axes(
figure_width = width_without_offsets + left_offset + right_offset
draw_region_width_frac = draw_region_width / figure_width
left_offset_frac = left_offset / figure_width
right_offset_frac = 1 - (len(panels) - 1) * left_offset_frac # noqa: F841
right_offset_frac = ( # noqa: F841 # TODO Does this need fixing?
1 - (len(panels) - 1) * left_offset_frac
)

if ax is None:
pl.figure(
Expand Down Expand Up @@ -708,9 +710,7 @@ def scatter_base(
)
for icolor, color in enumerate(colors):
ax = axs[icolor]
left = panel_pos[2][2 * icolor] # noqa: F841
bottom = panel_pos[0][0]
width = draw_region_width / figure_width # noqa: F841
height = panel_pos[1][0] - bottom
Y_sort = Y
if not is_color_like(color) and sort_order:
Expand Down Expand Up @@ -940,8 +940,8 @@ def make_pos(pos, node=root, currentLevel=0, parent=None, vert_loc=0):
if levels is None:
levels = make_levels({})
else:
levels = {level: {TOTAL: levels[level], CURRENT: 0} for level in levels}
vert_gap = height / (max([level for level in levels]) + 1)
levels = {k: {TOTAL: v, CURRENT: 0} for k, v in levels.items()}
vert_gap = height / (max(levels.keys()) + 1)
return make_pos({})


Expand Down
5 changes: 2 additions & 3 deletions scanpy/preprocessing/_deprecated/highly_variable_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,9 @@ def filter_genes_dispersion(
disp_mean_bin[one_gene_per_bin] = 0
# actually do the normalization
df['dispersion_norm'] = (
# use values here as index differs
df['dispersion'].values
- disp_mean_bin[ # use values here as index differs
df['mean_bin'].values
].values
- disp_mean_bin[df['mean_bin'].values].values
) / disp_std_bin[df['mean_bin'].values].values
elif flavor == 'cell_ranger':
from statsmodels import robust
Expand Down
6 changes: 2 additions & 4 deletions scanpy/preprocessing/_highly_variable_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,8 @@ def _highly_variable_genes_single_batch(
disp_mean_bin[one_gene_per_bin.values] = 0
# actually do the normalization
df['dispersions_norm'] = (
df['dispersions'].values
- disp_mean_bin[
df['mean_bin'].values
].values # use values here as index differs
df['dispersions'].values # use values here as index differs
- disp_mean_bin[df['mean_bin'].values].values
) / disp_std_bin[df['mean_bin'].values].values
elif flavor == 'cell_ranger':
from statsmodels import robust
Expand Down
8 changes: 5 additions & 3 deletions scanpy/preprocessing/_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,11 @@ def scale(
annotated with `'mean'` and `'std'` in `adata.var`.
"""
_check_array_function_arguments(layer=layer, obsm=obsm)
return scale_array(
data, zero_center=zero_center, max_value=max_value, copy=copy # noqa: F821
)
if layer is not None:
raise ValueError(f"`layer` argument inappropriate for value of type {type(X)}")
if obsm is not None:
raise ValueError(f"`obsm` argument inappropriate for value of type {type(X)}")
return scale_array(X, zero_center=zero_center, max_value=max_value, copy=copy)


@scale.register(np.ndarray)
Expand Down
4 changes: 2 additions & 2 deletions scanpy/tests/test_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
)


def test_pca_transform(array_type): # noqa: F811
def test_pca_transform(array_type):
A = array_type(A_list).astype('float32')
A_pca_abs = np.abs(A_pca)
A_svd_abs = np.abs(A_svd)
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_pca_sparse(pbmc3k_normalized):

# This will take a while to run, but irreproducibility may
# not show up for float32 unless the matrix is large enough
def test_pca_reproducible(pbmc3k_normalized, array_type, float_dtype): # noqa: F811
def test_pca_reproducible(pbmc3k_normalized, array_type, float_dtype):
pbmc = pbmc3k_normalized
pbmc.X = array_type(pbmc.X)

Expand Down
12 changes: 8 additions & 4 deletions scanpy/tools/_dpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ def check_adjacency(self):
for n_edges in range(1, np.max(n_edges_per_seg) + 1):
for iseg in range(self.segs_adjacency.shape[0]):
if n_edges_per_seg[iseg] == n_edges:
_ = self.segs_adjacency[iseg].todense().A1
neighbor_segs = ( # noqa: F841 TODO Evaluate whether to assign the variable or not
self.segs_adjacency[iseg].todense().A1
)
closest_points_other_segs = [
seg[np.argmin(self.distances_dpt[self.segs_tips[iseg][0], seg])]
for seg in self.segs
Expand Down Expand Up @@ -593,7 +595,9 @@ def detect_branching(
for iseg, seg_connects in enumerate(ssegs_connects)
if iseg != trunk
]
_ = segs_connects[iseg]
prev_connecting_points = segs_connects[ # noqa: F841 TODO Evaluate whether to assign the variable or not
iseg
]
for jseg_cnt, jseg in enumerate(prev_connecting_segments):
iseg_cnt = 0
for iseg_new, seg_new in enumerate(ssegs):
Expand Down Expand Up @@ -899,9 +903,9 @@ def _detect_branching_single_haghverdi16(self, Dseg, tips):
# permutations of tip cells
ps = [
[0, 1, 2], # start by computing distances from the first tip
[1, 2, 0], # -"- second tip
[1, 2, 0], # -"- second tip
[2, 0, 1],
Comment thread
Zethson marked this conversation as resolved.
Outdated
] # -"- third tip
] # -"- third tip
Comment thread
Zethson marked this conversation as resolved.
Outdated
for i, p in enumerate(ps):
ssegs.append(self.__detect_branching_haghverdi16(Dseg, tips[p]))
return ssegs
Expand Down
4 changes: 0 additions & 4 deletions scanpy/tools/_rank_genes_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def _ranks(X, mask=None, mask_rest=None):
if issparse(X):
merge = lambda tpl: vstack(tpl).toarray()
adapt = lambda X: X.toarray()

else:
merge = np.vstack
adapt = lambda X: X
Expand All @@ -49,7 +48,6 @@ def _ranks(X, mask=None, mask_rest=None):
get_chunk = lambda X, left, right: merge(
(X[mask, left:right], X[mask_rest, left:right])
)

else:
n_cells = X.shape[0]
get_chunk = lambda X, left, right: adapt(X[:, left:right])
Comment thread
Zethson marked this conversation as resolved.
Expand Down Expand Up @@ -171,7 +169,6 @@ def _basic_stats(self):

if issparse(self.X):
get_nonzeros = lambda X: X.getnnz(axis=0)

else:
get_nonzeros = lambda X: np.count_nonzero(X, axis=0)

Expand Down Expand Up @@ -744,7 +741,6 @@ def filter_rank_genes_groups(

if 'log1p' in adata.uns_keys() and adata.uns['log1p']['base'] is not None:
expm1_func = lambda x: np.expm1(x * np.log(adata.uns['log1p']['base']))

else:
expm1_func = np.expm1

Expand Down
Loading