Skip to content

Commit

Permalink
Enable FutureWarnings/DeprecationWarnings as errors (#734)
Browse files Browse the repository at this point in the history
As part of rapidsai/build-planning#26, enabling Python test failures for `FutureWarning`s and `DeprecationWarning`s

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)
  - Gigon Bae (https://github.com/gigony)

Approvers:
  - https://github.com/jakirkham

URL: #734
  • Loading branch information
mroeschke authored May 14, 2024
1 parent 6c467c6 commit 633aa35
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
6 changes: 6 additions & 0 deletions python/cucim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ testpaths = [
"src",
"tests",
]
filterwarnings = [
"error::FutureWarning",
"error::DeprecationWarning",
# https://github.com/cupy/cupy/blob/main/cupy/testing/_helper.py#L56
"ignore:pkg_resources is deprecated as an API:DeprecationWarning",
]

[tool.ruff]
# see: https://docs.astral.sh/ruff/rules/
Expand Down
8 changes: 5 additions & 3 deletions python/cucim/src/cucim/clara/converter/tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ def svs2tif(
logger.info(" num_workers: %d", num_workers)
logger.info(" compression: %s", compression)
logger.info(" output filename: %s", output_filename)

compressionargs = None
if compression is not None:
# handles only jpeg or None (no compression)
if compression.lower() == "jpeg":
compression = ("jpeg", 95)
compression = "jpeg"
compressionargs = {"level": 95}
else:
raise ValueError(
f"Unsupported compression: {compression}."
Expand Down Expand Up @@ -198,9 +199,10 @@ def svs2tif(
resolution=(
x_resolution // 2**level,
y_resolution // 2**level,
resolution_unit,
),
resolutionunit=resolution_unit,
compression=compression, # requires imagecodecs
compressionargs=compressionargs,
subfiletype=subfiletype,
)
logger.info("Done.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def distance_transform_edt(
if len(unique_sampling) == 1:
# In the isotropic case, can use the kernels without sample scaling
# and just adjust the final distance accordingly.
scalar_sampling = float(unique_sampling)
scalar_sampling = float(unique_sampling.item())
sampling = None

if image.ndim == 3:
Expand Down
8 changes: 4 additions & 4 deletions python/cucim/src/cucim/skimage/_vendored/_pearsonr.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,14 @@ def pearsonr(x, y, *, disable_checks=False):
# As explained in the docstring, the p-value can be computed as
# p = 2*dist.cdf(-abs(r))
# where dist is the beta distribution on [-1, 1] with shape parameters
# a = b = n/2 - 1. `special.btdtr` is the CDF for the beta distribution
# a = b = n/2 - 1. `special.betainc` is the CDF for the beta distribution
# on [0, 1]. To use it, we make the transformation x = (r + 1)/2; the
# shape parameters do not change. Then -abs(r) used in `cdf(-abs(r))`
# becomes x = (-abs(r) + 1)/2 = 0.5*(1 - abs(r)). (r is cast to float64
# to avoid a TypeError raised by btdtr when r is higher precision.)
# to avoid a TypeError raised by betainc when r is higher precision.)
ab = n / 2 - 1
# scalar valued, so use special.btdtr from SciPy, not CuPy
prob = 2 * special.btdtr(ab, ab, 0.5 * (1.0 - abs(r)))
# scalar valued, so use special.betainc from SciPy, not CuPy
prob = 2 * special.betainc(ab, ab, 0.5 * (1.0 - abs(r)))
if disable_checks:
# warn only based on output values to avoid overhead of host/device
# synchronization needed for the disabled checks above.
Expand Down
2 changes: 1 addition & 1 deletion python/cucim/src/cucim/skimage/exposure/exposure.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def cumulative_distribution(image, nbins=256):
>>> image = img_as_float(cp.array(data.camera()))
>>> hi = exposure.histogram(image)
>>> cdf = exposure.cumulative_distribution(image)
>>> cp.alltrue(cdf[0] == cp.cumsum(hi[0])/float(image.size))
>>> cp.all(cdf[0] == cp.cumsum(hi[0])/float(image.size))
array(True)
"""
hist, bin_centers = histogram(image, nbins)
Expand Down
4 changes: 2 additions & 2 deletions python/cucim/src/cucim/skimage/transform/tests/test_warps.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ def test_linear_warp_polar(dtype):
assert warped.dtype == _supported_float_type(dtype)
profile = warped.mean(axis=0)
peaks = cp.asnumpy(peak_local_max(profile))
assert np.alltrue([peak in radii for peak in peaks])
assert np.all([peak in radii for peak in peaks])


@pytest.mark.parametrize("dtype", [cp.float16, cp.float32, cp.float64])
Expand All @@ -906,7 +906,7 @@ def test_log_warp_polar(dtype):
peaks_coord = peak_local_max(profile)
peaks_coord.sort(axis=0)
gaps = cp.asnumpy(peaks_coord[1:] - peaks_coord[:-1])
assert np.alltrue([x >= 38 and x <= 40 for x in gaps])
assert np.all([x >= 38 and x <= 40 for x in gaps])


def test_invalid_scaling_polar():
Expand Down
8 changes: 6 additions & 2 deletions python/cucim/tests/util/gen_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import numpy as np
from tifffile import TiffWriter

COMPRESSION_MAP = {"jpeg": ("jpeg", 95), "deflate": "deflate", "raw": None}
COMPRESSION_MAP = {"jpeg": "jpeg", "deflate": "deflate", "raw": None}


class TiffGenerator:
Expand Down Expand Up @@ -57,8 +57,11 @@ def save_image(
raise RuntimeError("'image_data' is neithor list or numpy.ndarray")

compression = COMPRESSION_MAP.get(compression)
compressionargs = None
if not compression:
compression = ("jpeg", 95)
compression = "jpeg"
if compression == "jpeg":
compressionargs = {"level": 95}

# save as tif
tiff_file_name = str(
Expand All @@ -84,6 +87,7 @@ def save_image(
photometric="RGB",
planarconfig="CONTIG",
compression=compression, # requires imagecodecs
compressionargs=compressionargs,
subfiletype=1 if level else 0,
resolution=level_resolution,
resolutionunit=resolutionunit,
Expand Down

0 comments on commit 633aa35

Please sign in to comment.