1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
diff --git a/scipy/stats/tests/test_axis_nan_policy.py b/scipy/stats/tests/test_axis_nan_policy.py
index 32ab94087..0a0f88825 100644
--- a/scipy/stats/tests/test_axis_nan_policy.py
+++ b/scipy/stats/tests/test_axis_nan_policy.py
@@ -501,6 +501,18 @@ def _axis_nan_policy_test(hypotest, args, kwds, n_samples, n_outputs, paired,
assert_allclose(res_nd, res_1d, rtol=1e-14)
+# nan should not raise a exception in np.mean()
+# but does on some mips64el systems, triggering failure in some test cases
+# see https://github.com/scipy/scipy/issues/22360
+# and https://github.com/numpy/numpy/issues/23158
+def skip_nan_unexpected_exception():
+ try:
+ # should not raise an exception
+ with np.errstate(all='raise'):
+ x = np.asarray([1, 2, np.nan])
+ np.mean(x)
+ except:
+ pytest.skip("nan raises unexpected exception in numpy")
@pytest.mark.parametrize(("hypotest", "args", "kwds", "n_samples", "n_outputs",
"paired", "unpacker"), axis_nan_policy_cases)
@@ -516,6 +528,24 @@ def test_axis_nan_policy_axis_is_None(hypotest, args, kwds, n_samples,
def unpacker(res):
return res
+ # skip if nan emits unexpected RuntimeWarning in np.mean()
+ # seen on mips64el, https://github.com/scipy/scipy/issues/22360
+ # Only affects nan_policy "mixed-propagate" for selected hypotests
+ if data_generator=="mixed" and nan_policy=="propagate":
+ # only skip affected hypotests
+ if hypotest.__name__ in ["iqr", "ttest_ci",
+ "xp_mean_1samp", "xp_mean_2samp", "xp_var",
+ "weightedtau", "weightedtau_weighted"]:
+ skip_nan_unexpected_exception()
+ # all_nans-propagate-ttest_ci is also affected, via scalar multiply
+ if (data_generator=="all_nans" and nan_policy=="propagate"
+ and hypotest.__name__=="ttest_ci"):
+ skip_nan_unexpected_exception()
+ # mixed-omit-xp_var is also affected, via subtract
+ if (data_generator=="mixed" and nan_policy=="omit"
+ and hypotest.__name__=="xp_var"):
+ skip_nan_unexpected_exception()
+
rng = np.random.default_rng(0)
if data_generator == "empty":
|