Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#788)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.2.1 → v0.2.2](astral-sh/ruff-pre-commit@v0.2.1...v0.2.2)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* 🐛 Fix NPY002 Replace legacy `np.random.sample` call with `np.random.Generator`

* 📌 Pin dependency

* 🐛 Fix deepsource errors

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Shan E Ahmed Raza <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and shaneahmed authored Feb 20, 2024
1 parent a304598 commit 027ffdd
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/utils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions tiatoolbox/utils/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -374,23 +374,23 @@ 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:
msg = "Not support float `prediction` outside [0, 1]."
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:
Expand Down
10 changes: 5 additions & 5 deletions tiatoolbox/wsicore/wsireader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -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),
)
Expand Down

0 comments on commit 027ffdd

Please sign in to comment.