summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_function_base.py
diff options
context:
space:
mode:
authorJonathan Helmus <jjhelmus@gmail.com>2013-09-05 11:20:56 -0500
committerJonathan Helmus <jjhelmus@gmail.com>2013-09-13 17:03:37 -0500
commit4a084a0d77bbb7ade065e75d3602fd8b47369d76 (patch)
tree9a40376fc97924019eabaf2406cec9fcdc3620fd /numpy/lib/tests/test_function_base.py
parent07cbe999f84be4d1b0a35fdb15b53cc17bc4341d (diff)
downloadnumpy-4a084a0d77bbb7ade065e75d3602fd8b47369d76.tar.gz
MAINT: cleaning up percentile function.
Diffstat (limited to 'numpy/lib/tests/test_function_base.py')
-rw-r--r--numpy/lib/tests/test_function_base.py49
1 files changed, 10 insertions, 39 deletions
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 02597c78b..f0512420e 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1456,37 +1456,14 @@ class TestScoreatpercentile(TestCase):
[1, 1, 1]])
assert_array_equal(np.percentile(x, 50, axis=0), [[1, 1, 1]])
- def test_limit(self):
- x = np.arange(10)
- assert_equal(np.percentile(x, 50, limit=(2, 5)), 3.5)
- assert_equal(np.percentile([2, 3, 4, 5], 50), 3.5)
-
- assert_equal(np.percentile(x, 50, limit=(-1, 8)), 4)
- assert_equal(np.percentile([0, 1, 2, 3, 4, 5, 6, 7, 8], 50), 4)
-
- assert_equal(np.percentile(x, 50, limit=(4, 11)), 6.5)
- assert_equal(np.percentile([4, 5, 6, 7, 8, 9], 50, ), 6.5)
-
def test_linear(self):
# Test defaults
assert_equal(np.percentile(range(10), 50), 4.5)
- assert_equal(np.percentile(range(10), 50, (2, 7)), 4.5)
- assert_equal(np.percentile(range(100), 50, limit=(1, 8)), 4.5)
- assert_equal(np.percentile(np.array([1, 10, 100]), 50, (10, 100)), 55)
- assert_equal(np.percentile(np.array([1, 10, 100]), 50, (1, 10)), 5.5)
# explicitly specify interpolation_method 'fraction' (the default)
assert_equal(np.percentile(range(10), 50,
interpolation='linear'), 4.5)
- assert_equal(np.percentile(range(10), 50, limit=(2, 7),
- interpolation='linear'), 4.5)
- assert_equal(np.percentile(range(100), 50, limit=(1, 8),
- interpolation='linear'), 4.5)
- assert_equal(np.percentile(np.array([1, 10, 100]), 50, (10, 100),
- interpolation='linear'), 55)
- assert_equal(np.percentile(np.array([1, 10, 100]), 50, (1, 10),
- interpolation='linear'), 5.5)
def test_lower_higher(self):
@@ -1495,22 +1472,16 @@ class TestScoreatpercentile(TestCase):
interpolation='lower'), 4)
assert_equal(np.percentile(range(10), 50,
interpolation='higher'), 5)
- assert_equal(np.percentile(range(10), 50, (2, 7),
- interpolation='lower'), 4)
- assert_equal(np.percentile(range(10), 50, limit=(2, 7),
- interpolation='higher'), 5)
- assert_equal(np.percentile(range(100), 50, (1, 8),
- interpolation='lower'), 4)
- assert_equal(np.percentile(range(100), 50, (1, 8),
- interpolation='higher'), 5)
- assert_equal(np.percentile(np.array([1, 10, 100]), 50, (10, 100),
- interpolation='lower'), 10)
- assert_equal(np.percentile(np.array([1, 10, 100]), 50, limit=(10, 100),
- interpolation='higher'), 100)
- assert_equal(np.percentile(np.array([1, 10, 100]), 50, (1, 10),
- interpolation='lower'), 1)
- assert_equal(np.percentile(np.array([1, 10, 100]), 50, limit=(1, 10),
- interpolation='higher'), 10)
+
+ def test_midpoint(self):
+ assert_equal(np.percentile(range(10), 51,
+ interpolation='midpoint'), 4.5)
+
+ def test_closest(self):
+ assert_equal(np.percentile(range(10), 51,
+ interpolation='closest'), 5)
+ assert_equal(np.percentile(range(10), 49,
+ interpolation='closest'), 4)
def test_sequence(self):
x = np.arange(8) * 0.5