summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-05-02 22:36:12 -0700
committerGitHub <noreply@github.com>2019-05-02 22:36:12 -0700
commitf64ec0ca21466d3d461b88e232451c750982e9e6 (patch)
tree8274b398babaa0bed1208c70a1bf0dcbbcac2431 /numpy/lib
parent4b6b29afc06a639975d08f2e95dc3e1c36486188 (diff)
parentd7de4ad70d6794b36e4789e4f6146a884113bd66 (diff)
downloadnumpy-f64ec0ca21466d3d461b88e232451c750982e9e6.tar.gz
Merge pull request #13298 from navneet-nmk/diff-error
ENH: Added clearer exception for np.diff on 0-dimensional ndarray
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py2
-rw-r--r--numpy/lib/tests/test_function_base.py3
2 files changed, 5 insertions, 0 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index cab680751..7fa51d683 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1235,6 +1235,8 @@ def diff(a, n=1, axis=-1, prepend=np._NoValue, append=np._NoValue):
a = asanyarray(a)
nd = a.ndim
+ if nd == 0:
+ raise ValueError("diff requires input that is at least one dimensional")
axis = normalize_axis_index(axis, nd)
combined = []
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 6d32c365a..a5ae2eeed 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -696,6 +696,9 @@ class TestDiff(object):
assert_raises(np.AxisError, diff, x, axis=3)
assert_raises(np.AxisError, diff, x, axis=-4)
+ x = np.array(1.11111111111, np.float64)
+ assert_raises(ValueError, diff, x)
+
def test_nd(self):
x = 20 * rand(10, 20, 30)
out1 = x[:, :, 1:] - x[:, :, :-1]