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

🧑‍💻 Refine PatchExtractor Error Message #883

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions tests/test_patch_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,21 @@ def test_mask_based_patch_extractor_ndpi(
len_region1 = len(patches)

assert len_all > len_region2 > len_region1


def test_invalid_points_type() -> None:
"""Test invalid locations_list type for PointsPatchExtractor."""
img = np.zeros((256, 256, 3))
coords = [[10, 10]]
with pytest.raises(
TypeError,
match="Please input correct locations_list",
):
patchextraction.get_patch_extractor(
"point", input_img=img, locations_list=coords, patch_size=38
)

patches = patchextraction.get_patch_extractor(
"point", input_img=img, locations_list=np.array(coords), patch_size=38
)
assert len(patches) > 0
8 changes: 6 additions & 2 deletions tiatoolbox/tools/patchextraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from tiatoolbox import logger
from tiatoolbox.utils import misc
from tiatoolbox.utils.exceptions import MethodNotSupportedError
from tiatoolbox.utils.exceptions import FileNotSupportedError, MethodNotSupportedError
from tiatoolbox.utils.visualization import AnnotationRenderer
from tiatoolbox.wsicore import wsireader

Expand Down Expand Up @@ -772,7 +772,11 @@ def __init__(
pad_constant_values=pad_constant_values,
within_bound=within_bound,
)
self.locations_df = misc.read_locations(input_table=locations_list)
try:
self.locations_df = misc.read_locations(input_table=locations_list)
except (TypeError, FileNotSupportedError) as exc:
msg = "Please input correct locations_list"
raise TypeError(msg) from exc
self.locations_df["x"] = self.locations_df["x"] - int(
(self.patch_size[1] - 1) / 2,
)
Expand Down
2 changes: 1 addition & 1 deletion tiatoolbox/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def read_locations(
if isinstance(input_table, pd.DataFrame):
return __assign_unknown_class(input_table)

msg = "Please input correct image path or an ndarray image."
msg = "File type not supported."
Copy link
Member

Choose a reason for hiding this comment

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

You need to say which file types are supported.

raise TypeError(msg)


Expand Down
Loading