Skip to content

Commit

Permalink
Fix flake8 config and updates flake8 to 6.0 (#863)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
flying-sheep and pre-commit-ci[bot] authored Nov 29, 2022
1 parent 9ee3616 commit 57a602d
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 44 deletions.
56 changes: 29 additions & 27 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
# Can't yet be moved to the pyproject.toml due to https://github.com/PyCQA/flake8/issues/234
[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 =
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
# F821 Undefined name, can't import AnnData or it'd be a circular import
anndata/compat/_overloaded_dict.py: F821
# E721 comparing types, but we specifically are checking that we aren't getting subtypes (views)
anndata/tests/test_readwrite.py: E721

exclude =
.git,
__pycache__,
build,
docs/_build,
dist,

dist
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-autopep8
Expand Down
5 changes: 1 addition & 4 deletions anndata/_core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import numpy as np
import pandas as pd
from scipy.sparse import spmatrix, issparse
from ..compat import DaskArray

Index1D = Union[slice, int, str, np.int64, np.ndarray]
Index = Union[Index1D, Tuple[Index1D, Index1D], spmatrix]
from ..compat import DaskArray, Index, Index1D


def _normalize_indices(
Expand Down
1 change: 1 addition & 0 deletions anndata/_core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pandas.api.types import is_bool_dtype
from scipy import sparse

import anndata
from anndata._warnings import ImplicitModificationWarning
from .access import ElementRef
from ..compat import ZappyArray, DaskArray
Expand Down
3 changes: 2 additions & 1 deletion anndata/_io/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

try:
from .zarr import read_zarr
except ImportError as e: # noqa: F841
except ImportError as _e:
e = _e

def read_zarr(*_, **__):
raise e
Expand Down
4 changes: 2 additions & 2 deletions anndata/_io/specs/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def read_string_array(d):


@_REGISTRY.register_read_partial(H5Array, IOSpec("string-array", "0.2.0"))
def read_array_partial(d, items=None, indices=slice(None)):
def read_string_array_partial(d, items=None, indices=slice(None)):
return read_array_partial(d.asstr(), items=items, indices=indices)


Expand Down Expand Up @@ -642,7 +642,7 @@ def read_categorical(elem):

@_REGISTRY.register_read_partial(H5Group, IOSpec("categorical", "0.2.0"))
@_REGISTRY.register_read_partial(ZarrGroup, IOSpec("categorical", "0.2.0"))
def read_categorical(elem, *, items=None, indices=(slice(None),)):
def read_partial_categorical(elem, *, items=None, indices=(slice(None),)):
return pd.Categorical.from_codes(
codes=read_elem_partial(elem["codes"], indices=indices),
categories=read_elem(elem["categories"]),
Expand Down
3 changes: 1 addition & 2 deletions anndata/_io/specs/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from functools import singledispatch, wraps
from typing import Any, NamedTuple, Tuple, Type, Callable, Union


from anndata.compat import _read_attr, ZarrArray, ZarrGroup, H5Group, H5Array
from anndata._io.utils import report_write_key_on_error, report_read_key_on_error

Expand Down Expand Up @@ -125,7 +124,7 @@ def proc_spec_mapping(spec) -> IOSpec:


def get_spec(
elem: "Union[h5py.Dataset, h5py.Group, zarr.Group, zarr.Dataset]",
elem: "Union[H5Group, H5Array, ZarrGroup, ZarrArray]",
) -> IOSpec:
return proc_spec(
{
Expand Down
8 changes: 5 additions & 3 deletions anndata/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from functools import reduce, singledispatch, wraps
from codecs import decode
from inspect import signature, Parameter
from typing import Any, Collection, Union, Mapping, MutableMapping, Optional
from typing import Any, Tuple, Union, Mapping, MutableMapping, Optional
from warnings import warn

import h5py
Expand All @@ -17,12 +17,14 @@ class Empty:
pass


Index1D = Union[slice, int, str, np.int64, np.ndarray]
Index = Union[Index1D, Tuple[Index1D, Index1D], spmatrix]
H5Group = Union[h5py.Group, h5py.File]
H5Array = h5py.Dataset


# try importing zarr, dask, and zappy
from packaging import version
from packaging import version as _v

try:
from zarr.core import Array as ZarrArray
Expand Down Expand Up @@ -229,7 +231,7 @@ def _find_sparse_matrices(d: Mapping, n: int, keys: tuple, paths: list):
return paths


def _slice_uns_sparse_matrices(uns: MutableMapping, oidx: "Index1d", orig_n_obs: int):
def _slice_uns_sparse_matrices(uns: MutableMapping, oidx: "Index1D", orig_n_obs: int):
"""slice sparse spatrices of n_obs × n_obs in self.uns"""

from anndata._core.index import _subset
Expand Down
2 changes: 1 addition & 1 deletion anndata/experimental/multi_files/_anncollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ def dtype(self):
return _dtypes[self.attr][self.key]

attr = self[:1]
if hasattr(attr, dtype):
if hasattr(attr, "dtype"):
return attr.dtype
else:
return None
1 change: 1 addition & 0 deletions anndata/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

import anndata
from anndata.tests.helpers import subset_func

# TODO: Should be done in pyproject.toml, see anndata/conftest.py
warnings.filterwarnings("ignore", category=anndata.OldFormatWarning)
Expand Down
4 changes: 2 additions & 2 deletions anndata/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from functools import singledispatch, wraps
from string import ascii_letters
from typing import Tuple, Optional
from collections.abc import Mapping
from typing import Tuple, Optional, Type
from collections.abc import Mapping, Collection
import warnings

import h5py
Expand Down
1 change: 1 addition & 0 deletions anndata/tests/test_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from copy import deepcopy
from itertools import chain, product
from functools import partial, singledispatch
from typing import Any, List, Callable
import warnings

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion anndata/tests/test_inplace_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from anndata.tests.helpers import (
assert_equal,
gen_adata,
subset_func,
as_dense_dask_array,
)
from anndata.utils import asarray
Expand Down

0 comments on commit 57a602d

Please sign in to comment.