Skip to content

Commit

Permalink
fix: consistent handling of metrics for classes with no patches
Browse files Browse the repository at this point in the history
  • Loading branch information
martibosch committed Dec 11, 2024
1 parent 01c4845 commit 18220ed
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pylandstats/landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,17 @@ def _metric_reduce(
patch_metric_method_kwargs,
reduce_method,
):
try:
if self._num_patches_dict[class_val] < 1:
warnings.warn(
"There are no patches of class {class_val}, computing the"
" corresponding metrics will return nan values.",
RuntimeWarning,
)
return np.nan
except KeyError:
# `class_val` may be `None` (for landscape-level metrics)
pass
if patch_metric_method_kwargs is None:
patch_metrics = patch_metric_method(class_val=class_val)
else:
Expand Down

0 comments on commit 18220ed

Please sign in to comment.