diff --git a/continuous_integration/environment-3.10.yml b/continuous_integration/environment-3.10.yml index 96687c3e..96bdc9a0 100644 --- a/continuous_integration/environment-3.10.yml +++ b/continuous_integration/environment-3.10.yml @@ -10,7 +10,7 @@ dependencies: - flake8==6.0.0 - pytest==7.2.2 - pytest-cov==4.0.0 - - pytest-flake8==1.1.1 + - pytest-flake8==1.3.0 - pytest-timeout >=2.3.1 - dask==2024.4.1 - numpy==1.24.2 diff --git a/continuous_integration/environment-3.11.yml b/continuous_integration/environment-3.11.yml index b664e361..79959f80 100644 --- a/continuous_integration/environment-3.11.yml +++ b/continuous_integration/environment-3.11.yml @@ -10,7 +10,7 @@ dependencies: - flake8==6.0.0 - pytest==7.2.2 - pytest-cov==4.0.0 - - pytest-flake8==1.1.1 + - pytest-flake8==1.3.0 - pytest-timeout >=2.3.1 - dask==2024.4.1 - numpy==1.24.2 diff --git a/continuous_integration/environment-3.12.yml b/continuous_integration/environment-3.12.yml index a8848564..9f684c51 100644 --- a/continuous_integration/environment-3.12.yml +++ b/continuous_integration/environment-3.12.yml @@ -10,7 +10,7 @@ dependencies: - flake8==7.0.0 - pytest==8.2.0 - pytest-cov==5.0.0 - - pytest-flake8==1.1.1 + - pytest-flake8==1.3.0 - pytest-timeout >=2.3.1 - dask==2024.4.1 - numpy==1.26.4 diff --git a/continuous_integration/environment-3.9.yml b/continuous_integration/environment-3.9.yml index d4bc6378..2baa622f 100644 --- a/continuous_integration/environment-3.9.yml +++ b/continuous_integration/environment-3.9.yml @@ -10,7 +10,7 @@ dependencies: - flake8==7.0.0 - pytest==8.2.0 - pytest-cov==5.0.0 - - pytest-flake8==1.1.1 + - pytest-flake8==1.3.0 - pytest-timeout >=2.3.1 - dask==2024.4.1 - numpy==1.26.4 @@ -21,4 +21,4 @@ dependencies: - pandas==2.2.2 - twine==5.0.0 - pip: - - build==1.2.1 \ No newline at end of file + - build==1.2.1 diff --git a/dask_image/ndfilters/_generic.py b/dask_image/ndfilters/_generic.py index 82935952..e90963c9 100644 --- a/dask_image/ndfilters/_generic.py +++ b/dask_image/ndfilters/_generic.py @@ -26,7 +26,7 @@ def generic_filter(image, depth = _utils._get_depth(footprint.shape, origin) depth, boundary = _utils._get_depth_boundary(footprint.ndim, depth, "none") - if type(image._meta) == np.ndarray: + if type(image._meta) is np.ndarray: kwargs = {"extra_arguments": extra_arguments, "extra_keywords": extra_keywords} else: # pragma: no cover diff --git a/dask_image/ndfilters/_threshold.py b/dask_image/ndfilters/_threshold.py index 88082db4..39132ead 100644 --- a/dask_image/ndfilters/_threshold.py +++ b/dask_image/ndfilters/_threshold.py @@ -1,4 +1,3 @@ -import dask.array as da import numpy as np from ..dispatch._dispatch_ndfilters import dispatch_threshold_local_mean diff --git a/dask_image/ndfourier/_utils.py b/dask_image/ndfourier/_utils.py index 252e52d4..7071bace 100644 --- a/dask_image/ndfourier/_utils.py +++ b/dask_image/ndfourier/_utils.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -import functools -import operator import numbers import dask.array as da diff --git a/dask_image/ndinterp/__init__.py b/dask_image/ndinterp/__init__.py index a8181ddb..ddbbc916 100644 --- a/dask_image/ndinterp/__init__.py +++ b/dask_image/ndinterp/__init__.py @@ -20,9 +20,6 @@ ) from ..ndfilters._utils import _get_depth_boundary -from ..dispatch._dispatch_ndinterp import (dispatch_affine_transform, - dispatch_asarray) - __all__ = [ "affine_transform", "rotate", @@ -263,9 +260,9 @@ def rotate( The array is rotated in the plane defined by the two axes given by the `axes` parameter using spline interpolation of the requested order. - Chunkwise processing is performed using `dask_image.ndinterp.affine_transform`, - for which further parameters supported by the ndimage functions can be - passed as keyword arguments. + Chunkwise processing is performed using + `dask_image.ndinterp.affine_transform`, for which further parameters + supported by the ndimage functions can be passed as keyword arguments. Notes ----- @@ -386,10 +383,10 @@ def rotate( matrix_nd = np.eye(ndim) offset_nd = np.zeros(ndim) - for o_x,idx in enumerate(axes): + for o_x, idx in enumerate(axes): - matrix_nd[idx,axes[0]] = rot_matrix[o_x,0] - matrix_nd[idx,axes[1]] = rot_matrix[o_x,1] + matrix_nd[idx, axes[0]] = rot_matrix[o_x, 0] + matrix_nd[idx, axes[1]] = rot_matrix[o_x, 1] offset_nd[idx] = offset[o_x] diff --git a/dask_image/ndmeasure/__init__.py b/dask_image/ndmeasure/__init__.py index fdc96afc..31718b5d 100644 --- a/dask_image/ndmeasure/__init__.py +++ b/dask_image/ndmeasure/__init__.py @@ -14,7 +14,11 @@ from . import _utils from ._utils import _label -from ._utils._find_objects import _array_chunk_location, _find_bounding_boxes, _find_objects +from ._utils._find_objects import ( + _array_chunk_location, + _find_bounding_boxes, + _find_objects, +) __all__ = [ "area", @@ -242,12 +246,17 @@ def find_objects(label_image): arrays.append(delayed(_find_bounding_boxes)(block, array_location)) bag = db.from_sequence(arrays) - result = bag.fold(functools.partial(_find_objects, label_image.ndim), split_every=2).to_delayed() + result = bag.fold( + functools.partial(_find_objects, label_image.ndim), split_every=2 + ).to_delayed() meta = dd.utils.make_meta([(i, object) for i in range(label_image.ndim)]) - result = delayed(compute)(result)[0] # avoid the user having to call compute twice on result + # avoid the user having to call compute twice on result + result = delayed(compute)(result)[0] with dask_config.set({'dataframe.convert-string': False}): - result = dd.from_delayed(result, meta=meta, prefix="find-objects-", verify_meta=False) + result = dd.from_delayed( + result, meta=meta, prefix="find-objects-", verify_meta=False + ) return result @@ -327,7 +336,8 @@ def label(image, structure=None, wrap_axes=None): [0,1,0]] wrap_axes : tuple of int, optional - Whether labels should be wrapped across array boundaries, and if so which axes. + Whether labels should be wrapped across array boundaries, and if so + which axes. This feature is not present in `ndimage.label`. Examples: - (0,) only wrap across the 0th axis. @@ -381,7 +391,6 @@ def label(image, structure=None, wrap_axes=None): relabeled = _label.relabel_blocks(block_labeled, new_labeling) n = da.max(relabeled) - return (relabeled, n) diff --git a/dask_image/ndmeasure/_utils/_find_objects.py b/dask_image/ndmeasure/_utils/_find_objects.py index d9ad69c1..0037f35b 100644 --- a/dask_image/ndmeasure/_utils/_find_objects.py +++ b/dask_image/ndmeasure/_utils/_find_objects.py @@ -29,7 +29,13 @@ def _find_bounding_boxes(x, array_location): result = {} for val in unique_vals: positions = np.where(x == val) - slices = tuple(slice(np.min(pos) + array_location[i], np.max(pos) + 1 + array_location[i]) for i, pos in enumerate(positions)) + slices = tuple( + slice( + np.min(pos) + array_location[i], + np.max(pos) + 1 + array_location[i] + ) + for i, pos in enumerate(positions) + ) result[val] = slices column_names = [i for i in range(x.ndim)] # column names are: 0, 1, ... nD return pd.DataFrame.from_dict(result, orient='index', columns=column_names) @@ -46,7 +52,7 @@ def _combine_slices(slices): def _merge_bounding_boxes(x, ndim): - """Merge the bounding boxes describing objects over multiple image chunks.""" + "Merge the bounding boxes describing objects over multiple image chunks." x = x.dropna() data = {} # For each dimension in the array, diff --git a/dask_image/ndmeasure/_utils/_label.py b/dask_image/ndmeasure/_utils/_label.py index 7948c1ac..01544d48 100644 --- a/dask_image/ndmeasure/_utils/_label.py +++ b/dask_image/ndmeasure/_utils/_label.py @@ -243,14 +243,17 @@ def _chunk_faces(chunks, shape, structure, wrap_axes=None): for pos_structure_coord in np.array(np.where(structure)).T: # only consider forward neighbors - if min(pos_structure_coord) < 1 or \ - max(pos_structure_coord) < 2: continue + if min(pos_structure_coord) < 1 or max(pos_structure_coord) < 2: + continue - neigh_block = [curr_block[dim] + pos_structure_coord[dim] - 1 - for dim in range(ndim)] + neigh_block = [ + curr_block[dim] + pos_structure_coord[dim] - 1 + for dim in range(ndim) + ] if max([neigh_block[dim] >= block_summary.shape[dim] - for dim in range(ndim)]): continue + for dim in range(ndim)]): + continue # get current slice index ind_curr_block = block_summary[tuple(curr_block)] diff --git a/docs/conf.py b/docs/conf.py index d5fa39ef..9b9a6cf7 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,12 +18,6 @@ import dask_image._version -# If extensions (or modules to document with autodoc) are in another -# directory, add these directories to sys.path here. If the directory is -# relative to the documentation root, use os.path.abspath to make it -# absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) - # Get the project root dir, which is the parent dir of this cwd = os.getcwd() project_root = os.path.dirname(cwd) @@ -35,9 +29,6 @@ # -- General configuration --------------------------------------------- -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' - # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ @@ -53,9 +44,6 @@ # The suffix of source filenames. source_suffix = '.rst' -# The encoding of source files. -#source_encoding = 'utf-8-sig' - # The master toctree document. master_doc = 'index' @@ -76,47 +64,10 @@ else: display_version = version -# The language for content autogenerated by Sphinx. Refer to documentation -# for a list of supported languages. -#language = None - -# There are two options for replacing |today|: either, you set today to -# some non-false value, then it is used: -#today = '' -# Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' - # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] -# The reST default role (used for this markup: `text`) to use for all -# documents. -#default_role = None - -# If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True - -# If true, the current module name will be prepended to all description -# unit titles (such as .. function::). -#add_module_names = True - -# If true, sectionauthor and moduleauthor directives will be shown in the -# output. They are ignored by default. -#show_authors = False - -# The name of the Pygments (syntax highlighting) style to use. -# Commenting this out for now, if we register dask pygments, -# then eventually this line can be: -# pygments_style = "dask" - -# A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] - -# If true, keep warnings as "system message" paragraphs in the built -# documents. -#keep_warnings = False - # -- Options for HTML output ------------------------------------------- @@ -133,14 +84,6 @@ # a list of builtin themes. html_theme = 'dask_sphinx_theme' -# Theme options are theme-specific and customize the look and feel of a -# theme further. For a list of options available for each theme, see the -# documentation. -#html_theme_options = {} - -# Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] - # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". html_title = f"{project} {display_version} documentation" @@ -149,80 +92,13 @@ # html_title. html_short_title = f"{project} docs" -# The name of an image file (relative to this directory) to place at the -# top of the sidebar. -#html_logo = None - -# The name of an image file (within the static path) to use as favicon -# of the docs. This file should be a Windows icon file (.ico) being -# 16x16 or 32x32 pixels large. -#html_favicon = None - -# Add any paths that contain custom static files (such as style sheets) -# here, relative to this directory. They are copied after the builtin -# static files, so a file named "default.css" will overwrite the builtin -# "default.css". -#html_static_path = ['_static'] - -# If not '', a 'Last updated on:' timestamp is inserted at every page -# bottom, using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' - -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -#html_use_smartypants = True - -# Custom sidebar templates, maps document names to template names. -#html_sidebars = {} - -# Additional templates that should be rendered to pages, maps page names -# to template names. -#html_additional_pages = {} - -# If false, no module index is generated. -#html_domain_indices = True - -# If false, no index is generated. -#html_use_index = True - -# If true, the index is split into individual pages for each letter. -#html_split_index = False - -# If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True - -# If true, "Created using Sphinx" is shown in the HTML footer. -# Default is True. -#html_show_sphinx = True - -# If true, "(C) Copyright ..." is shown in the HTML footer. -# Default is True. -#html_show_copyright = True - -# If true, an OpenSearch description file will be output, and all pages -# will contain a tag referring to it. The value of this option -# must be the base URL from which the finished HTML is served. -#html_use_opensearch = '' - -# This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None - # Output file base name for HTML help builder. htmlhelp_basename = 'dask_imagedoc' # -- Options for LaTeX output ------------------------------------------ -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - #'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - #'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - #'preamble': '', -} +latex_elements = {} # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass @@ -233,26 +109,6 @@ u'John Kirkham', 'manual'), ] -# The name of an image file (relative to this directory) to place at -# the top of the title page. -#latex_logo = None - -# For "manual" documents, if this is true, then toplevel headings -# are parts, not chapters. -#latex_use_parts = False - -# If true, show page references after internal links. -#latex_show_pagerefs = False - -# If true, show URL addresses after external links. -#latex_show_urls = False - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] - -# If false, no module index is generated. -#latex_domain_indices = True - # -- Options for manual page output ------------------------------------ @@ -264,9 +120,6 @@ [u'John Kirkham'], 1) ] -# If true, show URL addresses after external links. -#man_show_urls = False - # -- Options for Texinfo output ---------------------------------------- @@ -282,18 +135,6 @@ 'Miscellaneous'), ] -# Documents to append as an appendix to all manuals. -#texinfo_appendices = [] - -# If false, no module index is generated. -#texinfo_domain_indices = True - -# How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' - -# If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False - # Run sphinx-apidoc before building docs. def run_apidoc(_): diff --git a/docs/release/generate_release_notes.py b/docs/release/generate_release_notes.py index 1f9a5101..c7b977eb 100644 --- a/docs/release/generate_release_notes.py +++ b/docs/release/generate_release_notes.py @@ -164,7 +164,7 @@ def add_to_users(users, new_user): # Now generate the release notes title = (f'{args.version} ({datetime.today().strftime("%Y-%m-%d")})') -title += f'\n' + f'-' * len(title) #title underline of same length as title +title += '\n' + '-' * len(title) # title underline of same length as title print(title) print( diff --git a/pyproject.toml b/pyproject.toml index abcdcc50..56989b0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,6 +69,6 @@ exclude = [ "tests*", ] -[tool.pytest] +[tool.pytest.ini_options] addopts = "--flake8" markers = "cupy" diff --git a/tests/test_dask_image/test_imread/test_cupy_imread.py b/tests/test_dask_image/test_imread/test_cupy_imread.py index a2182493..25f2714b 100644 --- a/tests/test_dask_image/test_imread/test_cupy_imread.py +++ b/tests/test_dask_image/test_imread/test_cupy_imread.py @@ -17,5 +17,5 @@ def test_cupy_imread(tmp_path): fh.write(a[i]) result = dask_image.imread.imread(fn, arraytype="cupy") - assert type(result._meta) == cupy.ndarray + assert type(result._meta) is cupy.ndarray assert type(result.compute()) == cupy.ndarray diff --git a/tests/test_dask_image/test_ndfilters/test__conv.py b/tests/test_dask_image/test_ndfilters/test__conv.py index 08869528..1bc3dae8 100644 --- a/tests/test_dask_image/test_ndfilters/test__conv.py +++ b/tests/test_dask_image/test_ndfilters/test__conv.py @@ -154,6 +154,8 @@ def test_convolutions_compare(sp_func, d, weights, origin=origin ) ) + + @pytest.mark.parametrize( "sp_func, da_func", [ @@ -164,25 +166,26 @@ def test_convolutions_compare(sp_func, @pytest.mark.parametrize( "weights", [ - np.ones((1,5)), - np.ones((5,1)), + np.ones((1, 5)), + np.ones((5, 1)), ] ) @pytest.mark.parametrize( "mode", - ["reflect","wrap","nearest","constant","mirror"]) + ["reflect", "wrap", "nearest", "constant", "mirror"] +) def test_convolutions_modes(sp_func, da_func, weights, mode): - a = np.arange(140).reshape(10,14) - d = da.from_array(a,chunks =(5, 7)) - + a = np.arange(140).reshape(10, 14) + d = da.from_array(a, chunks=(5, 7)) + da.utils.assert_eq( sp_func( - a, weights, mode = mode + a, weights, mode=mode ), da_func( - d, weights, mode = mode + d, weights, mode=mode ) - ) \ No newline at end of file + ) diff --git a/tests/test_dask_image/test_ndfilters/test__threshold.py b/tests/test_dask_image/test_ndfilters/test__threshold.py index 4f094c89..a5952c3e 100644 --- a/tests/test_dask_image/test_ndfilters/test__threshold.py +++ b/tests/test_dask_image/test_ndfilters/test__threshold.py @@ -5,6 +5,7 @@ from dask_image.ndfilters import threshold_local + @pytest.fixture def simple_test_image(): image = da.from_array(np.array( @@ -38,8 +39,9 @@ def test_threshold_local_gaussian(simple_test_image, block_size): out = threshold_local(simple_test_image, block_size, method='gaussian') assert_equal(ref, (simple_test_image > out).compute()) - out = threshold_local(simple_test_image, block_size, method='gaussian', - param=1./3.) + out = threshold_local( + simple_test_image, block_size, method='gaussian', param=1./3. + ) assert_equal(ref, (simple_test_image > out).compute()) @@ -93,7 +95,9 @@ def test_threshold_local_generic(simple_test_image): [25., 29., 28., 19., 10.], [34., 31., 23., 10., 4.]] ) - unchanged = threshold_local(simple_test_image, 1, method='generic', param=sum) + unchanged = threshold_local( + simple_test_image, 1, method='generic', param=sum + ) out = threshold_local(simple_test_image, 3, method='generic', param=sum) assert np.allclose(unchanged.compute(), simple_test_image.compute()) assert np.allclose(out.compute(), ref) diff --git a/tests/test_dask_image/test_ndfilters/test_cupy_threshold.py b/tests/test_dask_image/test_ndfilters/test_cupy_threshold.py index d3d26217..d268fc44 100644 --- a/tests/test_dask_image/test_ndfilters/test_cupy_threshold.py +++ b/tests/test_dask_image/test_ndfilters/test_cupy_threshold.py @@ -9,6 +9,7 @@ cupy = pytest.importorskip("cupy", minversion="5.0.0") + @pytest.fixture def simple_test_image(): image = da.from_array(cupy.array( @@ -43,8 +44,9 @@ def test_threshold_local_gaussian(simple_test_image, block_size): out = threshold_local(simple_test_image, block_size, method='gaussian') cupy.testing.assert_array_equal(ref, (simple_test_image > out).compute()) - out = threshold_local(simple_test_image, block_size, method='gaussian', - param=1./3.) + out = threshold_local( + simple_test_image, block_size, method='gaussian', param=1./3. + ) cupy.testing.assert_array_equal(ref, (simple_test_image > out).compute()) diff --git a/tests/test_dask_image/test_ndfourier/test_core.py b/tests/test_dask_image/test_ndfourier/test_core.py index f457533b..f8a0d841 100644 --- a/tests/test_dask_image/test_ndfourier/test_core.py +++ b/tests/test_dask_image/test_ndfourier/test_core.py @@ -4,7 +4,6 @@ import pytest import numpy as np -import scipy as sp import scipy.ndimage import dask.array as da @@ -211,8 +210,6 @@ def test_fourier_filter_non_positive(funcname, s): "fourier_uniform", ] ) - - @pytest.mark.parametrize( "real_fft, axis", [ diff --git a/tests/test_dask_image/test_ndinterp/test_affine_transformation.py b/tests/test_dask_image/test_ndinterp/test_affine_transformation.py index eeb4c4bd..ebcd251e 100644 --- a/tests/test_dask_image/test_ndinterp/test_affine_transformation.py +++ b/tests/test_dask_image/test_ndinterp/test_affine_transformation.py @@ -352,7 +352,7 @@ def test_affine_transform_parameter_formats(n): image_t_scale = dask_image.ndinterp.affine_transform(image, matrix_only_scaling, offset).compute() - assert (np.allclose(image_t_0, image_t_scale)) + assert np.allclose(image_t_0, image_t_scale) for matrix in [matrix_pre_homogeneous, matrix_homogeneous]: @@ -361,7 +361,7 @@ def test_affine_transform_parameter_formats(n): offset + 10., # ignored ).compute() - assert(np.allclose(image_t_0, image_t)) + assert np.allclose(image_t_0, image_t) # catch matrices that are not homogeneous transformation matrices with pytest.raises(ValueError): diff --git a/tests/test_dask_image/test_ndinterp/test_rotate.py b/tests/test_dask_image/test_ndinterp/test_rotate.py index 48003421..585a1c87 100644 --- a/tests/test_dask_image/test_ndinterp/test_rotate.py +++ b/tests/test_dask_image/test_ndinterp/test_rotate.py @@ -38,7 +38,6 @@ def validate_rotate(n=2, import cupy as cp image_da = image_da.map_blocks(cp.asarray) - # define resampling options output_chunks = [input_output_chunksize_per_dim[1]] * n @@ -72,7 +71,7 @@ def validate_rotate(n=2, @pytest.mark.parametrize("input_shape_per_dim", [25, 2]) @pytest.mark.parametrize("interp_order", - [0,1]) + [0, 1]) @pytest.mark.parametrize("input_output_chunksize_per_dim", [(16, 16), (16, 7), (7, 16)]) @pytest.mark.parametrize("random_seed", @@ -110,7 +109,7 @@ def test_rotate_cupy(n, input_output_chunksize_per_dim, random_seed): - cupy = pytest.importorskip("cupy", minversion="6.0.0") + cupy = pytest.importorskip("cupy", minversion="6.0.0") # noqa: F841 kwargs = dict() kwargs['n'] = n @@ -174,8 +173,10 @@ def test_rotate_axisdimensions(axes): validate_rotate(**kwargs) -@pytest.mark.parametrize("axes", - [[1, 2.2], [1, 'a'], [[0, 1], 1], [(0, 1), 1], [0, {}]]) +@pytest.mark.parametrize( + "axes", + [[1, 2.2], [1, 'a'], [[0, 1], 1], [(0, 1), 1], [0, {}]] +) def test_rotate_axistypes(axes): kwargs = dict() kwargs['axes'] = axes @@ -185,12 +186,12 @@ def test_rotate_axistypes(axes): @pytest.mark.parametrize( - "image", - [ - np.ones((3, 3)).astype(float), - np.ones((3, 3)).astype(int), - np.ones((3, 3)).astype(complex) - ] + "image", + [ + np.ones((3, 3)).astype(float), + np.ones((3, 3)).astype(int), + np.ones((3, 3)).astype(complex), + ] ) def test_rotate_dtype(image): image_t = da_ndinterp.rotate(image, 0, reshape=False) @@ -198,16 +199,14 @@ def test_rotate_dtype(image): def test_rotate_numpy_input(): - image = np.ones((3, 3)) - image_t = da_ndinterp.rotate(image, 0, reshape =False) + image_t = da_ndinterp.rotate(image, 0, reshape=False) assert image_t.shape == image.shape assert (da.from_array(image) == image_t).min() def test_rotate_minimal_input(): - image = np.ones((3, 3)) image_t = da_ndinterp.rotate(np.ones((3, 3)), 0) @@ -215,7 +214,6 @@ def test_rotate_minimal_input(): def test_rotate_type_consistency(): - image = da.ones((3, 3)) image_t = da_ndinterp.rotate(image, 0) @@ -225,7 +223,6 @@ def test_rotate_type_consistency(): @pytest.mark.cupy def test_rotate_type_consistency_gpu(): - cupy = pytest.importorskip("cupy", minversion="6.0.0") image = da.ones((3, 3)) @@ -238,7 +235,6 @@ def test_rotate_type_consistency_gpu(): def test_rotate_no_chunks_specified(): - image = da.ones((3, 3)) image_t = da_ndinterp.rotate(image, 0) diff --git a/tests/test_dask_image/test_ndmeasure/test_find_objects.py b/tests/test_dask_image/test_ndmeasure/test_find_objects.py index f4f84fe7..c4b20a9a 100644 --- a/tests/test_dask_image/test_ndmeasure/test_find_objects.py +++ b/tests/test_dask_image/test_ndmeasure/test_find_objects.py @@ -1,4 +1,3 @@ -from dask_image.ndmeasure._utils import _labeled_comprehension_delayed import dask.array as da import dask.dataframe as dd import numpy as np @@ -20,11 +19,11 @@ def label_image(): [ 0, 0, 0, 222, 222, 222, 222, 222, 222, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]) - """ + """ # noqa: E501 label_image = np.zeros((5, 10)).astype(int) - label_image[1:3,0:2] = 111 - label_image[3,3:-2] = 222 - label_image[0:2,-3:] = 333 + label_image[1:3, 0:2] = 111 + label_image[3, 3:-2] = 222 + label_image[0:2, -3:] = 333 label_image = da.from_array(label_image, chunks=(5, 5)) return label_image @@ -41,10 +40,10 @@ def label_image_with_empty_chunk(): [ 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 222, 222, 222], [ 0, 0, 0, 0, 0, 0]]) - """ + """ # noqa: E501 label_image = np.zeros((6, 6)).astype(int) - label_image[1:3,0:2] = 111 - label_image[4,3:] = 222 + label_image[1:3, 0:2] = 111 + label_image[4, 3:] = 222 label_image = da.from_array(label_image, chunks=(3, 3)) return label_image @@ -60,10 +59,10 @@ def test_find_objects(label_image): assert isinstance(result, dd.DataFrame) computed_result = result.compute() assert isinstance(computed_result, pd.DataFrame) - expected = pd.DataFrame.from_dict( - {0: {111: slice(1, 3), 222: slice(3, 4), 333: slice(0, 2)}, - 1: {111: slice(0, 2), 222: slice(3, 8), 333: slice(7, 10)}} - ) + expected = pd.DataFrame.from_dict({ + 0: {111: slice(1, 3), 222: slice(3, 4), 333: slice(0, 2)}, + 1: {111: slice(0, 2), 222: slice(3, 8), 333: slice(7, 10)}, + }) assert computed_result.equals(expected) @@ -73,11 +72,11 @@ def test_3d_find_objects(label_image): assert isinstance(result, dd.DataFrame) computed_result = result.compute() assert isinstance(computed_result, pd.DataFrame) - expected = pd.DataFrame.from_dict( - {0: {111: slice(1, 3), 222: slice(3, 4), 333: slice(0, 2)}, + expected = pd.DataFrame.from_dict({ + 0: {111: slice(1, 3), 222: slice(3, 4), 333: slice(0, 2)}, 1: {111: slice(0, 2), 222: slice(3, 8), 333: slice(7, 10)}, - 2: {111: slice(0, 2), 222: slice(0, 2), 333: slice(0, 2)}} - ) + 2: {111: slice(0, 2), 222: slice(0, 2), 333: slice(0, 2)}, + }) assert computed_result.equals(expected) @@ -86,8 +85,8 @@ def test_find_objects_with_empty_chunks(label_image_with_empty_chunk): assert isinstance(result, dd.DataFrame) computed_result = result.compute() assert isinstance(computed_result, pd.DataFrame) - expected = pd.DataFrame.from_dict( - {0: {111: slice(1, 3, None), 222: slice(4, 5, None)}, - 1: {111: slice(0, 2, None), 222: slice(3, 6, None)}} - ) + expected = pd.DataFrame.from_dict({ + 0: {111: slice(1, 3, None), 222: slice(4, 5, None)}, + 1: {111: slice(0, 2, None), 222: slice(3, 6, None)}, + }) assert computed_result.equals(expected) diff --git a/tests/test_dask_image/test_ndmorph/test__utils.py b/tests/test_dask_image/test_ndmorph/test__utils.py index 9b859e45..d0c5e5b8 100644 --- a/tests/test_dask_image/test_ndmorph/test__utils.py +++ b/tests/test_dask_image/test_ndmorph/test__utils.py @@ -111,7 +111,7 @@ def test_errs__get_brute_force(err_type, brute_force): def test__get_structure(expected, input, structure): result = _utils._get_structure(input, structure) - assert expected.dtype.type == result.dtype.type + assert expected.dtype.type is result.dtype.type assert np.array((expected == result).all())[()] @@ -138,7 +138,7 @@ def test__get_iterations(expected, iterations): ] ) def test__get_dtype(expected, a): - assert expected == _utils._get_dtype(a) + assert np.dtype(expected) is _utils._get_dtype(a) @pytest.mark.parametrize( @@ -172,7 +172,7 @@ def test__get_dtype(expected, a): def test__get_mask(expected, input, mask): result = _utils._get_mask(input, mask) - assert type(expected) == type(result) + assert type(expected) is type(result) if isinstance(expected, (np.ndarray, da.Array)): assert np.array((expected == result).all())[()]