diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 9df1550c6..919e58b44 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -30,7 +30,7 @@ jobs: sudo apt update sudo apt-get install -y libopenslide-dev openslide-tools libopenjp2-7 libopenjp2-tools python -m pip install --upgrade pip - python -m pip install ruff==0.2.1 pytest pytest-cov pytest-runner + python -m pip install ruff==0.2.2 pytest pytest-cov pytest-runner pip install -r requirements/requirements.txt - name: Cache tiatoolbox static assets uses: actions/cache@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ba7ff479f..60fb72afe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -68,7 +68,7 @@ repos: language: python - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.2.1 + rev: v0.2.2 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/requirements/requirements_dev.txt b/requirements/requirements_dev.txt index 7c58e0703..697d05d2a 100644 --- a/requirements/requirements_dev.txt +++ b/requirements/requirements_dev.txt @@ -12,7 +12,7 @@ pytest>=7.2.0 pytest-cov>=4.0.0 pytest-runner>=6.0 pytest-xdist[psutil] -ruff==0.2.1 # This will be updated by pre-commit bot to latest version +ruff==0.2.2 # This will be updated by pre-commit bot to latest version toml>=0.10.2 twine>=4.0.1 wheel>=0.37.1 diff --git a/tests/test_graph.py b/tests/test_graph.py index a423064a6..99c7bdbe8 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -87,7 +87,7 @@ def test_affinity_to_edge_index_fuzz_output_shape() -> None: for _ in range(1000): # Generate some random square inputs input_shape = [rng.integers(2, 10)] * 2 - affinity_matrix = np.random.sample(input_shape) + affinity_matrix = rng.random(input_shape) threshold = rng.random() # Convert to torch randomly if rng.random() > 0.5: @@ -108,7 +108,7 @@ def test_affinity_to_edge_index_invalid_fuzz_input_shape() -> None: for _ in range(100): input_shape = [rng.integers(2, 10)] * 2 input_shape[1] -= 1 - affinity_matrix = np.random.sample(input_shape) + affinity_matrix = rng.random(input_shape) threshold = rng.random() # Convert to torch randomly if rng.random() > 0.5: diff --git a/tiatoolbox/utils/misc.py b/tiatoolbox/utils/misc.py index 5164c7917..4d3d4b66b 100644 --- a/tiatoolbox/utils/misc.py +++ b/tiatoolbox/utils/misc.py @@ -983,7 +983,7 @@ def select_cv2_interpolation(scale_factor: float | npt.NDArray[np.float64]) -> s interpolation type """ - if np.any(scale_factor > 1.0): # noqa: PLR2004 + if np.any(scale_factor > 1.0): return "cubic" return "area" diff --git a/tiatoolbox/utils/transforms.py b/tiatoolbox/utils/transforms.py index 36c43ec21..05396c798 100644 --- a/tiatoolbox/utils/transforms.py +++ b/tiatoolbox/utils/transforms.py @@ -141,7 +141,7 @@ def imresize( scale_factor_array = img.shape[:2][::-1] / np.array(output_size_array) # Return original if scale factor is 1 - if np.all(scale_factor_array == 1.0): # noqa: PLR2004 + if np.all(scale_factor_array == 1.0): return img # Get appropriate cv2 interpolation enum diff --git a/tiatoolbox/utils/visualization.py b/tiatoolbox/utils/visualization.py index e75b7376c..ba26fe47f 100644 --- a/tiatoolbox/utils/visualization.py +++ b/tiatoolbox/utils/visualization.py @@ -119,7 +119,7 @@ def overlay_prediction_mask( msg, ) if np.issubdtype(img.dtype, np.floating): - if not (img.max() <= 1.0 and img.min() >= 0): # noqa: PLR2004 + if not (img.max() <= 1.0 and img.min() >= 0): msg = "Not support float `img` outside [0, 1]." raise ValueError(msg) img = np.array(img * 255, dtype=np.uint8) @@ -157,7 +157,7 @@ def overlay_prediction_mask( cv2.addWeighted(rgb_prediction, alpha, overlay, 1 - alpha, 0, overlay) overlay = overlay.astype(np.uint8) - if min_val > 0.0: # noqa: PLR2004 + if min_val > 0.0: overlay[~prediction_sel] = img[~prediction_sel] if ax is None and not return_ax: @@ -310,7 +310,7 @@ def overlay_probability_map( overlay[overlay > 255.0] = 255.0 # noqa: PLR2004 overlay = overlay.astype(np.uint8) - if min_val > 0.0: # noqa: PLR2004 + if min_val > 0.0: overlay[~prediction_sel] = img[~prediction_sel] if ax is None and not return_ax: @@ -374,7 +374,7 @@ def _validate_overlay_probability_map( msg, ) - if prediction.max() > 1.0: # noqa: PLR2004 + if prediction.max() > 1.0: msg = "Not support float `prediction` outside [0, 1]." raise ValueError(msg) if prediction.min() < 0: @@ -382,15 +382,15 @@ def _validate_overlay_probability_map( raise ValueError(msg) # if `min_val` is defined, only display the overlay for areas with prob > min_val - if min_val < 0.0: # noqa: PLR2004 + if min_val < 0.0: msg = f"`min_val={min_val}` is not between [0, 1]." raise ValueError(msg) - if min_val > 1.0: # noqa: PLR2004 + if min_val > 1.0: msg = f"`min_val={min_val}` is not between [0, 1]." raise ValueError(msg) if np.issubdtype(img.dtype, np.floating): - if img.max() > 1.0: # noqa: PLR2004 + if img.max() > 1.0: msg = "Not support float `img` outside [0, 1]." raise ValueError(msg) if img.min() < 0: diff --git a/tiatoolbox/wsicore/wsireader.py b/tiatoolbox/wsicore/wsireader.py index dd38a53b1..f7e4cacf5 100644 --- a/tiatoolbox/wsicore/wsireader.py +++ b/tiatoolbox/wsicore/wsireader.py @@ -99,8 +99,8 @@ def is_zarr(path: Path) -> bool: _ = zarr.open(str(path), mode="r") except Exception: # skipcq: PYL-W0703 # noqa: BLE001 return False - else: - return True + + return True def is_ngff( # noqa: PLR0911 @@ -1578,7 +1578,7 @@ def save_tiles( # Rescale to the correct objective value if rescale != 1: - im = utils.transforms.imresize(img=im, scale_factor=(1 / rescale)) + im = utils.transforms.imresize(img=im, scale_factor=1 / rescale) img_save_name = ( "_".join( @@ -5520,7 +5520,7 @@ def read_rect( utils.transforms.background_composite(base_region, alpha=True), ) im_region = Image.fromarray(im_region) - if self.alpha < 1.0: # noqa: PLR2004 + if self.alpha < 1.0: im_region.putalpha( im_region.getchannel("A").point(lambda i: i * self.alpha), ) @@ -5713,7 +5713,7 @@ class docstrings for more information. utils.transforms.background_composite(base_region, alpha=True), ) im_region = Image.fromarray(im_region) - if self.alpha < 1.0: # noqa: PLR2004 + if self.alpha < 1.0: im_region.putalpha( im_region.getchannel("A").point(lambda i: i * self.alpha), )