Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable FutureWarnings/DeprecationWarnings as errors #734

Merged
merged 7 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this to be user facing? Or do we want to keep this internal for now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we make it user facing, we may need to add some additional validation on the input. I would be fine with just keeping it internal for now.

@gigony do you have a preference?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grlee77 @jakirkham
It seems appropriate to update it now since this API change has been in effect since July 2022.
https://github.com/cgohlke/tifffile/blame/ec6be6289db1b8b7327bb98816a764c95b9b7299/README.rst#L519

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grlee77 were there particular thoughts you had on what input validation would look like?

Wonder if tifffile's own validation would work for us

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep internal for now and merge this change as it is.

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
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)
mroeschke marked this conversation as resolved.
Show resolved Hide resolved
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