You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test result: when an all-masked array is used as data input, distance_metric returns data element 0 instead of masked or --, with numpy=2 and certain (not all!) metrics
valeriupredoi
changed the title
Preprocessor distance_metric returns value 0 instead of -- (masked element) with numpy==2.0.0 for certain metrics
[Numpy2] Preprocessor distance_metric returns value 0 instead of -- (masked element) with numpy==2.0.0 for certain metrics
Jun 19, 2024
the sqrt is not computed correctly in the case of masked arrays: one needs to account both for Numpy and Dask:
npx=get_array_module(squared_error)
# need masked sqrt for numpy >=2.0# and dask.array.reductions.safe_sqrt for Dask# otherwise results will be computed ignoring masksifnpx.__name__=="dask.array":
da_squared_error=npx.ma.average(squared_error,
axis=axis,
weights=weights)
rmse=npx.reductions.safe_sqrt(da_squared_error)
else:
rmse=npx.ma.sqrt(
npx.ma.average(squared_error, axis=axis, weights=weights)
)
ie if np.sqrt() ignores masks then da.sqrt() will too, see numpy/numpy#25635 that may be fixed, or not - the issue is pretty old now wrt Numpy2 timeline, so better we have the patch in our code
valeriupredoi
changed the title
[Numpy2] Preprocessor distance_metric returns value 0 instead of -- (masked element) with numpy==2.0.0 for certain metrics
[Numpy2] Preprocessor distance_metric returns value 0 instead of -- (masked element) with numpy==2.0.0 for metrics that use np.sqrt or da.sqrtJun 21, 2024
tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py
distance_metric
returns data element 0 instead ofmasked
or--
, with numpy=2 and certain (not all!) metricscould be Scipy could be something else, this needs a bit of due dilligence 🍺
The text was updated successfully, but these errors were encountered: