summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2014-08-24 17:54:35 +0200
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-08-24 18:02:11 +0200
commit040d0408f4cdb0a472e654acd68c8e1c3fbd84f7 (patch)
treee1b98f4a9d56f6890522508108961d3887fa3288 /numpy/lib
parentbbb7c3fbcdc2ddfcf79317661be2b99b1f6617e3 (diff)
downloadnumpy-040d0408f4cdb0a472e654acd68c8e1c3fbd84f7.tar.gz
BUG: don't overwrite input percentile arrays
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py2
-rw-r--r--numpy/lib/tests/test_function_base.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 0a1d05f77..087d1cbb5 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -3031,7 +3031,7 @@ def percentile(a, q, axis=None, out=None,
array([ 3.5])
"""
- q = asarray(q, dtype=np.float64)
+ q = array(q, dtype=np.float64, copy=True)
r, k = _ureduce(a, func=_percentile, q=q, axis=axis, out=out,
overwrite_input=overwrite_input,
interpolation=interpolation)
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index ee38b3573..f70d7dda0 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1858,6 +1858,14 @@ class TestScoreatpercentile(TestCase):
np.percentile(a, [50])
assert_equal(a, np.array([2, 3, 4, 1]))
+ def test_no_p_overwrite(self):
+ p = np.linspace(0., 100., num=5)
+ np.percentile(np.arange(100.), p, interpolation="midpoint")
+ assert_array_equal(p, np.linspace(0., 100., num=5))
+ p = np.linspace(0., 100., num=5).tolist()
+ np.percentile(np.arange(100.), p, interpolation="midpoint")
+ assert_array_equal(p, np.linspace(0., 100., num=5).tolist())
+
def test_percentile_overwrite(self):
a = np.array([2, 3, 4, 1])
b = np.percentile(a, [50], overwrite_input=True)