diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-01-17 13:04:44 +0100 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-01-17 13:51:55 +0100 |
commit | 2144aa713b607a5f0592525d9b36adca332e9d51 (patch) | |
tree | 36b9ea77fc851691a88ec81e253c6bf283c97d8c /numpy/lib | |
parent | 305c302e0e5a877f81fcaf9ef00a289528f8466e (diff) | |
download | numpy-2144aa713b607a5f0592525d9b36adca332e9d51.tar.gz |
BUG: fix wrong masked median for some special cases
the masked nans which are equivalent to valid infs must be replaced
with infs earlier otherwise the inf is lost in the masked sum of the low
and high part.
Closes gh-8487
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/tests/test_nanfunctions.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_nanfunctions.py b/numpy/lib/tests/test_nanfunctions.py index e1942338b..2b310457b 100644 --- a/numpy/lib/tests/test_nanfunctions.py +++ b/numpy/lib/tests/test_nanfunctions.py @@ -710,6 +710,18 @@ class TestNanFunctions_Median(TestCase): a = np.array([[inf, inf], [inf, inf]]) assert_equal(np.nanmedian(a, axis=1), inf) + a = np.array([[inf, 7, -inf, -9], + [-10, np.nan, np.nan, 5], + [4, np.nan, np.nan, inf]], + dtype=np.float32) + if inf > 0: + assert_equal(np.nanmedian(a, axis=0), [4., 7., -inf, 5.]) + assert_equal(np.nanmedian(a), 4.5) + else: + assert_equal(np.nanmedian(a, axis=0), [-10., 7., -inf, -9.]) + assert_equal(np.nanmedian(a), -2.5) + assert_equal(np.nanmedian(a, axis=-1), [-1., -2.5, inf]) + for i in range(0, 10): for j in range(1, 10): a = np.array([([np.nan] * i) + ([inf] * j)] * 2) |