From d5bac99c07e5846b8c7ac3ca40d301b5b05a4f4b Mon Sep 17 00:00:00 2001 From: jakirkham Date: Sat, 2 Feb 2019 18:18:39 +1100 Subject: [PATCH] Use flake8 (#93) * Require flake8 be installed on CI * Require `flake8` and `pytest-flake8` for testing As the tests make use of flake8 (specifically a pytest plugin for flake8), require `flake8` and `pytest-flake8`. * Ensure flake8 is run with pytest Uses the flake8 plugin for pytest to ensure that flake8 checks are run as part of pytest. * Exclude versioneer and docs from flake8 * Drop unused external imports caught by flake8 These imports were probably used for code that no longer needs them. So go ahead and drop these unused imports. * Wrap long warning line Running flake8 picked out this line as too long. This wraps it some to try and fix this issue. * Break up warning string across multiple lines To fit the 79 character limit constraint, split this warning into two strings on two lines that are concatenated. * Drop some internal unused imports Some internal imports are unused according to flake8. So we drop them here to fix these flake8 errors. * Avoid flake8 unused import error To workaround flake8 unused import errors where we know these functions are imported and used elsewhere, go ahead and perform trivial assignments to make use of these functions. This still passes the tests and removes the flake8 errors. * Reorder imports in ndfilters Make sure that all imports in `ndfilters` happen before other statements to fix flake8 errors. * Ignore `lambda` assignment with flake8 We are not really interested in flake8's `lambda` assignment rule in these cases. So simply tell flake8 to ignore these lines. * Adjust line wrapping of `lambda` Removes the need for the `\`, which seems to be causing issues with `flake8`. * Disable the flake8 lambda assignment on both lines For some reason disabling this flake8 error on the second line is not sufficient. So disable it on the first lines as well. * Drop flake8 noqa from second `lambda` line This `noqa` seems to have no effect. So just drop it to avoid having these in excess. * Remove whitespace before `:` for flake8 * Have flake8 ignore `lambda` assignment * Wrap parameterized arguments As flake8 complains the line length is too long here, wrap these arguments to fit them within the recommended line length. * Wrap test parameterized arguments To fit the recommended line length, wrap the test function's parameterized arguments. * Ignore `lambda` assignment with flake8 We are not really interested in flake8's `lambda` assignment rule in these cases. So simply tell flake8 to ignore these lines. * Wrap parameterized arguments As flake8 complains the line length is too long here, wrap these arguments to fit them within the recommended line length. * Wrap parameterized arguments As flake8 complains the line length is too long here, wrap these arguments to fit them within the recommended line length. * Ignore `lambda` assignment with flake8 We are not really interested in flake8's `lambda` assignment rule in these cases. So simply tell flake8 to ignore these lines. * Trim whitespace before `:` in `lambda` for flake8 * Ignore `lambda` assignment with flake8 We are not really interested in flake8's `lambda` assignment rule in these cases. So simply tell flake8 to ignore these lines. * Drop extra blank line * Compare `str`s with `==`s instead of `is` * Drop unused import As the `operator` module is not being used in this test module, drop it from the imports. * Allow a couple of long lines These are a little annoying to wrap currently. So simply tell flake8 to not worry about these. * Require flake8 and pytest plugin on Python 3.5 As Python 3.5 is not supported in conda-forge any more, this uses the slightly older versions of packages that work with Python 3.5 in order to run the flake8 tests there as well. * Switch to `[tool:pytest]` in `setup.cfg` As the `[pytest]` section in `setup.cfg` seems to be deprecated and raises errors when used with newer pytest versions, switch to using `[tool:pytest]` instead. This seems to work ok even with old versions of pytest used with Python 3.5. * Cleanup SciPy check in `test_fourier_filter_type` As flake8 did not like how this line was formatted, we simplify it a bit and adjust the indentation to make it happier. * Cleanup SciPy check in `test_measure_props` As flake8 did not like how this line was formatted, we simplify it a bit and adjust the indentation to make it happier. --- .appveyor_support/environments/tst_py27.yml | 2 + .appveyor_support/environments/tst_py35.yml | 2 + .appveyor_support/environments/tst_py36.yml | 2 + .appveyor_support/environments/tst_py37.yml | 2 + .circleci/environments/tst_py27.yml | 2 + .circleci/environments/tst_py35.yml | 2 + .circleci/environments/tst_py36.yml | 2 + .circleci/environments/tst_py37.yml | 2 + .travis_support/environments/tst_py27.yml | 2 + .travis_support/environments/tst_py35.yml | 2 + .travis_support/environments/tst_py36.yml | 2 + .travis_support/environments/tst_py37.yml | 2 + dask_image/ndfilters/__init__.py | 37 ++++++++++--------- dask_image/ndfilters/_diff.py | 2 - dask_image/ndfilters/_generic.py | 3 -- dask_image/ndfilters/_order.py | 3 -- dask_image/ndfilters/_smooth.py | 6 +-- dask_image/ndfilters/_utils.py | 10 ++--- dask_image/ndfourier/_utils.py | 3 +- dask_image/ndmeasure/__init__.py | 6 ++- dask_image/ndmeasure/_utils.py | 3 -- dask_image/ndmorph/_ops.py | 2 - dask_image/ndmorph/_utils.py | 10 +++-- setup.cfg | 5 ++- setup.py | 2 + tests/test_dask_image/test__pycompat.py | 2 +- .../test_ndfilters/test__gaussian.py | 14 ++++--- .../test_ndfilters/test__generic.py | 4 +- .../test_ndfilters/test__order.py | 30 ++++++++++----- .../test_ndfilters/test__smooth.py | 2 +- .../test_ndfilters/test__utils.py | 9 ++--- .../test_ndfourier/test_core.py | 12 +++--- .../test_ndmeasure/test__utils.py | 4 +- .../test_ndmeasure/test_core.py | 8 ++-- .../test_ndmorph/test__utils.py | 2 +- 35 files changed, 119 insertions(+), 84 deletions(-) diff --git a/.appveyor_support/environments/tst_py27.yml b/.appveyor_support/environments/tst_py27.yml index 0ea60973..517af3e5 100644 --- a/.appveyor_support/environments/tst_py27.yml +++ b/.appveyor_support/environments/tst_py27.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.7.2 - pytest==3.8.2 + - pytest-flake8==1.0.4 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.appveyor_support/environments/tst_py35.yml b/.appveyor_support/environments/tst_py35.yml index c85959af..e102a886 100644 --- a/.appveyor_support/environments/tst_py35.yml +++ b/.appveyor_support/environments/tst_py35.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.5.0 - pytest==3.8.1 + - pytest-flake8==1.0.1 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.appveyor_support/environments/tst_py36.yml b/.appveyor_support/environments/tst_py36.yml index df5e0532..19c15a2e 100644 --- a/.appveyor_support/environments/tst_py36.yml +++ b/.appveyor_support/environments/tst_py36.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.7.2 - pytest==3.8.2 + - pytest-flake8==1.0.4 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.appveyor_support/environments/tst_py37.yml b/.appveyor_support/environments/tst_py37.yml index b1e4e37a..8fc5feec 100644 --- a/.appveyor_support/environments/tst_py37.yml +++ b/.appveyor_support/environments/tst_py37.yml @@ -8,7 +8,9 @@ dependencies: - pip==19.0.1 - wheel==0.32.3 - coverage==4.5.2 + - flake8==3.7.2 - pytest==4.2.0 + - pytest-flake8==1.0.4 - dask==1.1.1 - numpy==1.15.4 - scipy==1.2.0 diff --git a/.circleci/environments/tst_py27.yml b/.circleci/environments/tst_py27.yml index 0ea60973..517af3e5 100644 --- a/.circleci/environments/tst_py27.yml +++ b/.circleci/environments/tst_py27.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.7.2 - pytest==3.8.2 + - pytest-flake8==1.0.4 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.circleci/environments/tst_py35.yml b/.circleci/environments/tst_py35.yml index c85959af..e102a886 100644 --- a/.circleci/environments/tst_py35.yml +++ b/.circleci/environments/tst_py35.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.5.0 - pytest==3.8.1 + - pytest-flake8==1.0.1 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.circleci/environments/tst_py36.yml b/.circleci/environments/tst_py36.yml index df5e0532..19c15a2e 100644 --- a/.circleci/environments/tst_py36.yml +++ b/.circleci/environments/tst_py36.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.7.2 - pytest==3.8.2 + - pytest-flake8==1.0.4 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.circleci/environments/tst_py37.yml b/.circleci/environments/tst_py37.yml index 24729a0b..31bdc3ad 100644 --- a/.circleci/environments/tst_py37.yml +++ b/.circleci/environments/tst_py37.yml @@ -8,7 +8,9 @@ dependencies: - pip==19.0.1 - wheel==0.32.3 - coverage==4.5.2 + - flake8==3.7.2 - pytest==4.2.0 + - pytest-flake8==1.0.4 - dask==1.1.1 - numpy==1.16.0 - scipy==1.2.0 diff --git a/.travis_support/environments/tst_py27.yml b/.travis_support/environments/tst_py27.yml index 0ea60973..517af3e5 100644 --- a/.travis_support/environments/tst_py27.yml +++ b/.travis_support/environments/tst_py27.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.7.2 - pytest==3.8.2 + - pytest-flake8==1.0.4 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.travis_support/environments/tst_py35.yml b/.travis_support/environments/tst_py35.yml index c85959af..e102a886 100644 --- a/.travis_support/environments/tst_py35.yml +++ b/.travis_support/environments/tst_py35.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.5.0 - pytest==3.8.1 + - pytest-flake8==1.0.1 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.travis_support/environments/tst_py36.yml b/.travis_support/environments/tst_py36.yml index df5e0532..19c15a2e 100644 --- a/.travis_support/environments/tst_py36.yml +++ b/.travis_support/environments/tst_py36.yml @@ -8,7 +8,9 @@ dependencies: - pip==18.0 - wheel==0.31.1 - coverage==4.5.1 + - flake8==3.7.2 - pytest==3.8.2 + - pytest-flake8==1.0.4 - dask==0.16.1 - numpy==1.11.3 - scipy==1.1.0 diff --git a/.travis_support/environments/tst_py37.yml b/.travis_support/environments/tst_py37.yml index 24729a0b..31bdc3ad 100644 --- a/.travis_support/environments/tst_py37.yml +++ b/.travis_support/environments/tst_py37.yml @@ -8,7 +8,9 @@ dependencies: - pip==19.0.1 - wheel==0.32.3 - coverage==4.5.2 + - flake8==3.7.2 - pytest==4.2.0 + - pytest-flake8==1.0.4 - dask==1.1.1 - numpy==1.16.0 - scipy==1.2.0 diff --git a/dask_image/ndfilters/__init__.py b/dask_image/ndfilters/__init__.py index 7de9e407..4a3c8b6e 100644 --- a/dask_image/ndfilters/__init__.py +++ b/dask_image/ndfilters/__init__.py @@ -8,38 +8,25 @@ convolve, correlate, ) -convolve.__module__ = __name__ -correlate.__module__ = __name__ from ._diff import ( laplace, ) -laplace.__module__ = __name__ - from ._edge import ( prewitt, sobel, ) -prewitt.__module__ = __name__ -sobel.__module__ = __name__ - from ._gaussian import ( gaussian_filter, gaussian_gradient_magnitude, gaussian_laplace, ) -gaussian_filter.__module__ = __name__ -gaussian_gradient_magnitude.__module__ = __name__ -gaussian_laplace.__module__ = __name__ - from ._generic import ( generic_filter, ) -generic_filter.__module__ = __name__ - from ._order import ( minimum_filter, @@ -48,14 +35,30 @@ rank_filter, percentile_filter, ) + +from ._smooth import ( + uniform_filter, +) + + +convolve.__module__ = __name__ +correlate.__module__ = __name__ + +laplace.__module__ = __name__ + +prewitt.__module__ = __name__ +sobel.__module__ = __name__ + +gaussian_filter.__module__ = __name__ +gaussian_gradient_magnitude.__module__ = __name__ +gaussian_laplace.__module__ = __name__ + +generic_filter.__module__ = __name__ + minimum_filter.__module__ = __name__ median_filter.__module__ = __name__ maximum_filter.__module__ = __name__ rank_filter.__module__ = __name__ percentile_filter.__module__ = __name__ - -from ._smooth import ( - uniform_filter, -) uniform_filter.__module__ = __name__ diff --git a/dask_image/ndfilters/_diff.py b/dask_image/ndfilters/_diff.py index 1a7c6800..88a95fe0 100644 --- a/dask_image/ndfilters/_diff.py +++ b/dask_image/ndfilters/_diff.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- -import numbers - import scipy.ndimage.filters from . import _utils diff --git a/dask_image/ndfilters/_generic.py b/dask_image/ndfilters/_generic.py index e6a72079..64245ba1 100644 --- a/dask_image/ndfilters/_generic.py +++ b/dask_image/ndfilters/_generic.py @@ -1,9 +1,6 @@ # -*- coding: utf-8 -*- -import numbers - -import numpy import scipy.ndimage.filters from . import _utils diff --git a/dask_image/ndfilters/_order.py b/dask_image/ndfilters/_order.py index e943ba9f..517311a3 100644 --- a/dask_image/ndfilters/_order.py +++ b/dask_image/ndfilters/_order.py @@ -1,9 +1,6 @@ # -*- coding: utf-8 -*- -import numbers - -import numpy import scipy.ndimage.filters from . import _utils diff --git a/dask_image/ndfilters/_smooth.py b/dask_image/ndfilters/_smooth.py index ab96eeec..2a136d75 100644 --- a/dask_image/ndfilters/_smooth.py +++ b/dask_image/ndfilters/_smooth.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- -import numbers - -import numpy import scipy.ndimage.filters from . import _utils from ._gaussian import gaussian_filter +gaussian_filter = gaussian_filter + + @_utils._update_wrapper(scipy.ndimage.filters.uniform_filter) def uniform_filter(input, size=3, diff --git a/dask_image/ndfilters/_utils.py b/dask_image/ndfilters/_utils.py index 9bdeb88c..ce0c31c5 100644 --- a/dask_image/ndfilters/_utils.py +++ b/dask_image/ndfilters/_utils.py @@ -9,14 +9,14 @@ import numpy -from .._pycompat import imap, irange, izip, strlike, unicode +from .._pycompat import irange, izip, strlike def _get_docstring(func): # Drop the output parameter from the docstring. - split_doc_params = lambda s: \ - re.subn("( [A-Za-z]+ : )", "\0\\1", s)[0].split("\0") - drop_doc_param = lambda s: not s.startswith(" output : ") + split_doc_params = lambda s: re.subn( # noqa: E731 + "( [A-Za-z]+ : )", "\0\\1", s)[0].split("\0") + drop_doc_param = lambda s: not s.startswith(" output : ") # noqa: E731 func_doc = "" if func.__doc__ is None else func.__doc__ cleaned_docstring = "".join([ l for l in split_doc_params(func_doc) if drop_doc_param(l) @@ -87,7 +87,7 @@ def _get_depth_boundary(ndim, depth, boundary=None): if not isinstance(boundary, collections.Mapping): raise TypeError("Unexpected type for `boundary`.") - type_check = lambda b: (b is None) or isinstance(b, strlike) + type_check = lambda b: (b is None) or isinstance(b, strlike) # noqa: E731 if not all(map(type_check, boundary.values())): raise TypeError("Expected string-like values for `boundary`.") diff --git a/dask_image/ndfourier/_utils.py b/dask_image/ndfourier/_utils.py index 8834c8c4..07e10e44 100644 --- a/dask_image/ndfourier/_utils.py +++ b/dask_image/ndfourier/_utils.py @@ -1,14 +1,13 @@ # -*- coding: utf-8 -*- -import itertools import numbers import numpy import dask.array -from .._pycompat import imap, irange, izip +from .._pycompat import izip def _get_freq_grid(shape, chunks, dtype=float): diff --git a/dask_image/ndmeasure/__init__.py b/dask_image/ndmeasure/__init__.py index e383a378..1c59f6a6 100644 --- a/dask_image/ndmeasure/__init__.py +++ b/dask_image/ndmeasure/__init__.py @@ -211,7 +211,11 @@ def label(input, structure=None): input = dask.array.asarray(input) if not all([len(c) == 1 for c in input.chunks]): - warn("``input`` does not have 1 chunk in all dimensions; it will be consolidated first", RuntimeWarning) + warn( + "``input`` does not have 1 chunk in all dimensions; " + "it will be consolidated first", + RuntimeWarning + ) label_func = dask.delayed(scipy.ndimage.label, nout=2) label, num_features = label_func(input, structure) diff --git a/dask_image/ndmeasure/_utils.py b/dask_image/ndmeasure/_utils.py index 6817ac7e..beab30b7 100644 --- a/dask_image/ndmeasure/_utils.py +++ b/dask_image/ndmeasure/_utils.py @@ -3,7 +3,6 @@ from __future__ import division -import operator import warnings import numpy @@ -11,8 +10,6 @@ import dask import dask.array -from .. import _pycompat - def _norm_input_labels_index(input, labels=None, index=None): """ diff --git a/dask_image/ndmorph/_ops.py b/dask_image/ndmorph/_ops.py index 9ec17b13..2e15b799 100644 --- a/dask_image/ndmorph/_ops.py +++ b/dask_image/ndmorph/_ops.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- -import numpy - import dask.array from . import _utils diff --git a/dask_image/ndmorph/_utils.py b/dask_image/ndmorph/_utils.py index 93abf196..494e0ad2 100644 --- a/dask_image/ndmorph/_utils.py +++ b/dask_image/ndmorph/_utils.py @@ -9,15 +9,17 @@ import dask.array from ..ndfilters._utils import ( - _get_docstring, _update_wrapper, _get_depth_boundary, - _get_size, _get_origin, - _get_depth, - _get_footprint + _get_depth ) +_update_wrapper = _update_wrapper +_get_depth_boundary = _get_depth_boundary +_get_origin = _get_origin +_get_depth = _get_depth + def _get_structure(input, structure): # Create square connectivity as default diff --git a/setup.cfg b/setup.cfg index 0f8eac77..4092b28e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,4 +10,7 @@ parentdir_prefix = dask-image universal = 1 [flake8] -exclude = docs +exclude = docs/conf.py,versioneer.py + +[tool:pytest] +addopts = --flake8 diff --git a/setup.py b/setup.py index 63f63ad2..0f3c57cd 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,9 @@ def run_tests(self): ] test_requirements = [ + "flake8 >=3.4.1", "pytest >=3.0.5", + "pytest-flake8 >=0.8.1", "scikit-image >=0.12.3", ] diff --git a/tests/test_dask_image/test__pycompat.py b/tests/test_dask_image/test__pycompat.py index aa5c18ea..8de5197c 100644 --- a/tests/test_dask_image/test__pycompat.py +++ b/tests/test_dask_image/test__pycompat.py @@ -16,7 +16,7 @@ def test_irange(): def test_imap(): - r = dask_image._pycompat.imap(lambda e : e ** 2, [0, 1, 2, 3]) + r = dask_image._pycompat.imap(lambda e: e ** 2, [0, 1, 2, 3]) assert not isinstance(r, list) diff --git a/tests/test_dask_image/test_ndfilters/test__gaussian.py b/tests/test_dask_image/test_ndfilters/test__gaussian.py index d09f7516..d0d5ece2 100644 --- a/tests/test_dask_image/test_ndfilters/test__gaussian.py +++ b/tests/test_dask_image/test_ndfilters/test__gaussian.py @@ -113,7 +113,7 @@ def test_gaussian_filter_shape_type(da_func): ] ) def test_gaussian_filter_comprehensions(da_func): - da_wfunc = lambda arr: da_func(arr, 1.0, truncate=4.0) + da_wfunc = lambda arr: da_func(arr, 1.0, truncate=4.0) # noqa: E731 np.random.seed(0) @@ -140,9 +140,12 @@ def test_gaussian_filter_comprehensions(da_func): @pytest.mark.parametrize( "sp_func, da_func", [ - (sp_ndf.gaussian_filter, da_ndf.gaussian_filter), - (sp_ndf.gaussian_gradient_magnitude, da_ndf.gaussian_gradient_magnitude), - (sp_ndf.gaussian_laplace, da_ndf.gaussian_laplace), + (sp_ndf.gaussian_filter, + da_ndf.gaussian_filter), + (sp_ndf.gaussian_gradient_magnitude, + da_ndf.gaussian_gradient_magnitude), + (sp_ndf.gaussian_laplace, + da_ndf.gaussian_laplace), ] ) def test_gaussian_filters_compare(sp_func, da_func, sigma, truncate): @@ -185,7 +188,8 @@ def test_gaussian_filters_compare(sp_func, da_func, sigma, truncate): (sp_ndf.gaussian_filter, da_ndf.gaussian_filter), ] ) -def test_gaussian_derivative_filters_compare(sp_func, da_func, order, sigma, truncate): +def test_gaussian_derivative_filters_compare(sp_func, da_func, + order, sigma, truncate): s = (100, 110) a = np.arange(float(np.prod(s))).reshape(s) d = da.from_array(a, chunks=(50, 55)) diff --git a/tests/test_dask_image/test_ndfilters/test__generic.py b/tests/test_dask_image/test_ndfilters/test__generic.py index 9178299d..07797e8c 100644 --- a/tests/test_dask_image/test_ndfilters/test__generic.py +++ b/tests/test_dask_image/test_ndfilters/test__generic.py @@ -67,7 +67,7 @@ def test_generic_filters_params(da_func, ] ) def test_generic_filter_shape_type(da_func): - function = lambda x: x + function = lambda x: x # noqa: E731 size = 1 a = np.arange(140.0).reshape(10, 14) @@ -119,7 +119,7 @@ def test_generic_filter_identity(sp_func, ] ) def test_generic_filter_comprehensions(da_func): - da_wfunc = lambda arr: da_func(arr, lambda x: x, 1) + da_wfunc = lambda arr: da_func(arr, lambda x: x, 1) # noqa: E731 np.random.seed(0) diff --git a/tests/test_dask_image/test_ndfilters/test__order.py b/tests/test_dask_image/test_ndfilters/test__order.py index b11341ae..6e1d0b8d 100644 --- a/tests/test_dask_image/test_ndfilters/test__order.py +++ b/tests/test_dask_image/test_ndfilters/test__order.py @@ -91,11 +91,16 @@ def test_ordered_filter_shape_type(da_func, @pytest.mark.parametrize( "sp_func, da_func, extra_kwargs", [ - (sp_ndf.minimum_filter, da_ndf.minimum_filter, {}), - (sp_ndf.median_filter, da_ndf.median_filter, {}), - (sp_ndf.maximum_filter, da_ndf.maximum_filter, {}), - (sp_ndf.rank_filter, da_ndf.rank_filter, {"rank": 0}), - (sp_ndf.percentile_filter, da_ndf.percentile_filter, {"percentile": 0}), + (sp_ndf.minimum_filter, + da_ndf.minimum_filter, {}), + (sp_ndf.median_filter, + da_ndf.median_filter, {}), + (sp_ndf.maximum_filter, + da_ndf.maximum_filter, {}), + (sp_ndf.rank_filter, + da_ndf.rank_filter, {"rank": 0}), + (sp_ndf.percentile_filter, + da_ndf.percentile_filter, {"percentile": 0}), ] ) @pytest.mark.parametrize( @@ -150,11 +155,16 @@ def test_order_comprehensions(da_func, kwargs): @pytest.mark.parametrize( "sp_func, da_func, extra_kwargs", [ - (sp_ndf.minimum_filter, da_ndf.minimum_filter, {}), - (sp_ndf.median_filter, da_ndf.median_filter, {}), - (sp_ndf.maximum_filter, da_ndf.maximum_filter, {}), - (sp_ndf.rank_filter, da_ndf.rank_filter, {"rank": 1}), - (sp_ndf.percentile_filter, da_ndf.percentile_filter, {"percentile": 10}), + (sp_ndf.minimum_filter, + da_ndf.minimum_filter, {}), + (sp_ndf.median_filter, + da_ndf.median_filter, {}), + (sp_ndf.maximum_filter, + da_ndf.maximum_filter, {}), + (sp_ndf.rank_filter, + da_ndf.rank_filter, {"rank": 1}), + (sp_ndf.percentile_filter, + da_ndf.percentile_filter, {"percentile": 10}), ] ) @pytest.mark.parametrize( diff --git a/tests/test_dask_image/test_ndfilters/test__smooth.py b/tests/test_dask_image/test_ndfilters/test__smooth.py index 5d101da7..90536185 100644 --- a/tests/test_dask_image/test_ndfilters/test__smooth.py +++ b/tests/test_dask_image/test_ndfilters/test__smooth.py @@ -52,7 +52,7 @@ def test_uniform_shape_type(): def test_uniform_comprehensions(): - da_func = lambda arr: da_ndf.uniform_filter(arr, 1, origin=0) + da_func = lambda arr: da_ndf.uniform_filter(arr, 1, origin=0) # noqa: E731 np.random.seed(0) diff --git a/tests/test_dask_image/test_ndfilters/test__utils.py b/tests/test_dask_image/test_ndfilters/test__utils.py index c74768a6..a268b52d 100644 --- a/tests/test_dask_image/test_ndfilters/test__utils.py +++ b/tests/test_dask_image/test_ndfilters/test__utils.py @@ -13,7 +13,7 @@ def test__get_docstring(): - f = lambda : 0 + f = lambda: 0 # noqa: E731 result = _utils._get_docstring(f) @@ -37,13 +37,12 @@ def test__get_docstring(): def test__update_wrapper(): - f = lambda : 0 + f = lambda: 0 # noqa: E731 @_utils._update_wrapper(f) def g(): return f() - assert f.__name__ == g.__name__ expected = """ @@ -68,10 +67,10 @@ def g(): @pytest.mark.parametrize( "err_type, ndim, depth, boundary", [ - (TypeError, lambda : 0, 1, None), + (TypeError, lambda: 0, 1, None), (TypeError, 1.0, 1, None), (ValueError, -1, 1, None), - (TypeError, 1, lambda : 0, None), + (TypeError, 1, lambda: 0, None), (TypeError, 1, 1.0, None), (ValueError, 1, -1, None), (ValueError, 1, (1, 1), None), diff --git a/tests/test_dask_image/test_ndfourier/test_core.py b/tests/test_dask_image/test_ndfourier/test_core.py index 4c5ce68e..955c1ea0 100644 --- a/tests/test_dask_image/test_ndfourier/test_core.py +++ b/tests/test_dask_image/test_ndfourier/test_core.py @@ -96,13 +96,11 @@ def test_fourier_filter_identity(funcname, s): ] ) def test_fourier_filter_type(funcname, upcast_type, dtype): - if (LooseVersion(sp.__version__) >= "1.0.0" and ( - dtype is np.int64 or - dtype is np.float64 - ) and ( - funcname is "fourier_gaussian" or - funcname is "fourier_uniform" - )): + if ( + LooseVersion(sp.__version__) >= "1.0.0" and + dtype in [np.int64, np.float64] and + funcname in ["fourier_gaussian", "fourier_uniform"] + ): pytest.skip( "SciPy 1.0.0+ doesn't handle double precision values correctly." ) diff --git a/tests/test_dask_image/test_ndmeasure/test__utils.py b/tests/test_dask_image/test_ndmeasure/test__utils.py index 39a29e00..8cb6c84e 100644 --- a/tests/test_dask_image/test_ndmeasure/test__utils.py +++ b/tests/test_dask_image/test_ndmeasure/test__utils.py @@ -3,8 +3,6 @@ from __future__ import absolute_import -import operator - import pytest import numpy as np @@ -44,7 +42,7 @@ def test__norm_input_labels_index(): lbls = (a < 0.5).astype(int) d_lbls = da.from_array(lbls, chunks=d.chunks) - d_n, d_lbls_n, ind_n = dask_image.ndmeasure._utils._norm_input_labels_index( + d_n, d_lbls_n, ind_n = dask_image.ndmeasure._utils._norm_input_labels_index( # noqa: E501 d, d_lbls, ind ) diff --git a/tests/test_dask_image/test_ndmeasure/test_core.py b/tests/test_dask_image/test_ndmeasure/test_core.py index 52eb42a9..4f3dac42 100644 --- a/tests/test_dask_image/test_ndmeasure/test_core.py +++ b/tests/test_dask_image/test_ndmeasure/test_core.py @@ -123,9 +123,11 @@ def test_measure_props(funcname, shape, chunks, has_lbls, ind): # See the linked issue for details. # ref: https://github.com/scipy/scipy/issues/7706 - if (funcname == "median" and - ind is not None and - not np.in1d(np.atleast_1d(ind), lbls).all()): + if ( + funcname == "median" and + ind is not None and + not np.in1d(np.atleast_1d(ind), lbls).all() + ): pytest.skip("SciPy's `median` mishandles missing labels.") assert np.allclose(np.array(a_r), np.array(d_r), equal_nan=True) diff --git a/tests/test_dask_image/test_ndmorph/test__utils.py b/tests/test_dask_image/test_ndmorph/test__utils.py index 16631f3c..f64fdcf5 100644 --- a/tests/test_dask_image/test_ndmorph/test__utils.py +++ b/tests/test_dask_image/test_ndmorph/test__utils.py @@ -97,7 +97,7 @@ def test_errs__get_brute_force(err_type, brute_force): ), ( numpy.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]], dtype=bool), - (dask.array.arange(100, chunks=10).reshape(10, 10) % 2).astype(bool), + (dask.array.arange(100, chunks=10).reshape(10, 10) % 2).astype(bool), # noqa: E501 None ), (