The nan* functions do not work due to a bug in the bound calculation
At this line, bounds are erroneously set to nan.
Thus, at this line, the condition becomes False, as np.allclose returns False by default with nan.
This makes this exception to trigger erroneously.
To fix: replace np.min and np.max with np.nanmin and np.nanmax
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/diffprivlib/tools/utils.py", line 267, in nanmean
return _mean(array, epsilon=epsilon, bounds=bounds, axis=axis, dtype=dtype, keepdims=keepdims,
File "/usr/local/lib/python3.8/dist-packages/diffprivlib/tools/utils.py", line 290, in _mean
array = clip_to_bounds(np.ravel(array), bounds)
File "/usr/local/lib/python3.8/dist-packages/diffprivlib/validation.py", line 195, in clip_to_bounds
raise ValueError(f"For non-scalar bounds, input array must be 2-dimensional. Got {array.ndim} dimensions.")
ValueError: For non-scalar bounds, input array must be 2-dimensional. Got 1 dimensions.
Describe the bug
The
nan*
functions do not work due to a bug in the bound calculation At this line, bounds are erroneously set tonan
. Thus, at this line, the condition becomes False, asnp.allclose
returnsFalse
by default withnan
. This makes this exception to trigger erroneously.To fix: replace
np.min
andnp.max
withnp.nanmin
andnp.nanmax
To Reproduce
Just run the code:
It raises: