10000 Merge pull request #4989 from juliantaylor/percentile-fix · numpy/numpy@3f5ae6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f5ae6d

Browse files
committed
Merge pull request #4989 from juliantaylor/percentile-fix
BUG: don't overwrite input percentile arrays
2 parents 181e72c + 040d040 commit 3f5ae6d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

numpy/lib/function_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3036,7 +3036,7 @@ def percentile(a, q, axis=None, out=None,
30363036
array([ 3.5])
30373037
30383038
"""
3039-
q = asarray(q, dtype=np.float64)
3039+
q = array(q, dtype=np.float64, copy=True)
30403040
r, k = _ureduce(a, func=_percentile, q=q, axis=axis, out=out,
30413041
overwrite_input=overwrite_input,
30423042
interpolation=interpolation)

numpy/lib/tests/test_function_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,14 @@ def test_percentile_no_overwrite(self):
18651865
np.percentile(a, [50])
18661866
assert_equal(a, np.array([2, 3, 4, 1]))
18671867

1868+
def test_no_p_overwrite(self):
1869+
p = np.linspace(0., 100., num=5)
1870+
np.percentile(np.arange(100.), p, interpolation="midpoint")
1871+
assert_array_equal(p, np.linspace(0., 100., num=5))
1872+
p = np.linspace(0., 100., num=5).tolist()
1873+
np.percentile(np.arange(100.), p, interpolation="midpoint")
1874+
assert_array_equal(p, np.linspace(0., 100., num=5).tolist())
1875+
18681876
def test_percentile_overwrite(self):
18691877
a = np.array([2, 3, 4, 1])
18701878
b = np.percentile(a, [50], overwrite_input=True)

0 commit comments

Comments
 (0)
0