summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_nanfunctions.py
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2014-05-31 13:20:43 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-06-02 23:47:24 +0200
commit99ff7a7cad36fcb5ba239bccd87a4f01ad25a1c1 (patch)
tree6bdb286e11684864ba3ff86a0d913a95863235b1 /numpy/lib/tests/test_nanfunctions.py
parent0ae36289aa5104fce4e40c63ba46e19365f33b5d (diff)
downloadnumpy-99ff7a7cad36fcb5ba239bccd87a4f01ad25a1c1.tar.gz
ENH: use masked median for small multidimensional nanmedians
Diffstat (limited to 'numpy/lib/tests/test_nanfunctions.py')
-rw-r--r--numpy/lib/tests/test_nanfunctions.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_nanfunctions.py b/numpy/lib/tests/test_nanfunctions.py
index 3fcfca218..c5af61434 100644
--- a/numpy/lib/tests/test_nanfunctions.py
+++ b/numpy/lib/tests/test_nanfunctions.py
@@ -5,7 +5,7 @@ import warnings
import numpy as np
from numpy.testing import (
run_module_suite, TestCase, assert_, assert_equal, assert_almost_equal,
- assert_raises
+ assert_raises, assert_array_equal
)
@@ -580,6 +580,22 @@ class TestNanFunctions_Median(TestCase):
assert_almost_equal(res, resout)
assert_almost_equal(res, tgt)
+ def test_small_large(self):
+ # test the small and large code paths, current cutoff 400 elements
+ for s in [5, 20, 51, 200, 1000]:
+ d = np.random.randn(4, s)
+ # Randomly set some elements to NaN:
+ w = np.random.randint(0, d.size, size=d.size // 5)
+ d.ravel()[w] = np.nan
+ d[:,0] = 1. # ensure at least one good value
+ # use normal median without nans to compare
+ tgt = []
+ for x in d:
+ nonan = np.compress(~np.isnan(x), x)
+ tgt.append(np.median(nonan, overwrite_input=True))
+
+ assert_array_equal(np.nanmedian(d, axis=-1), tgt)
+
def test_result_values(self):
tgt = [np.median(d) for d in _rdat]
res = np.nanmedian(_ndat, axis=1)