Summary
wpm() (Weighted Product Model) in xrspatial/mcda/combine.py does not validate that input criterion values are positive. The product prod(x_i ** w_i) is undefined for x_i <= 0 when w_i is non-integer:
0 ** 0.5 == 0, so a single zero collapses the entire product to zero, masking bugs in upstream standardization.
(-1) ** 0.5 == nan, so negative inputs silently propagate NaN through the output without an error.
The function docstring states inputs should be standardized 0-1, but no runtime check enforces this.
Reproduction
from xrspatial.mcda.combine import wpm
import xarray as xr, numpy as np
data = xr.Dataset({
'a': xr.DataArray(np.array([[0.0, 1.0]])),
'b': xr.DataArray(np.array([[-1.0, 2.0]])),
})
weights = {'a': 0.5, 'b': 0.5}
r = wpm(data, weights)
# returns [[nan, 1.41]] with no warning
Context
This is a sibling Cat 3 finding from the mcda security audit. The NaN-weight Cat 3 was fixed in #1311 / #1312. PR #1312 noted in its description that wpm accepting zero-base/negative-weight combinations was a deferred follow-up. This issue tracks that work.
Proposed fix
Validate criterion values before the product. Raise ValueError naming the offending variable when any value is <= 0 (NaN should still propagate, since that is the documented behavior tested in test_wpm_nan).
Summary
wpm()(Weighted Product Model) inxrspatial/mcda/combine.pydoes not validate that input criterion values are positive. The productprod(x_i ** w_i)is undefined forx_i <= 0whenw_iis non-integer:0 ** 0.5 == 0, so a single zero collapses the entire product to zero, masking bugs in upstream standardization.(-1) ** 0.5 == nan, so negative inputs silently propagate NaN through the output without an error.The function docstring states inputs should be standardized 0-1, but no runtime check enforces this.
Reproduction
Context
This is a sibling Cat 3 finding from the mcda security audit. The NaN-weight Cat 3 was fixed in #1311 / #1312. PR #1312 noted in its description that
wpmaccepting zero-base/negative-weight combinations was a deferred follow-up. This issue tracks that work.Proposed fix
Validate criterion values before the product. Raise
ValueErrornaming the offending variable when any value is<= 0(NaN should still propagate, since that is the documented behavior tested intest_wpm_nan).