diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/arraypad.py | 3 | ||||
-rw-r--r-- | numpy/lib/tests/test_arraypad.py | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py index 2dad99c34..294a68950 100644 --- a/numpy/lib/arraypad.py +++ b/numpy/lib/arraypad.py @@ -1406,6 +1406,9 @@ def pad(array, pad_width, mode, **kwargs): newmat = _append_min(newmat, pad_after, chunk_after, axis) elif mode == 'reflect': + if narray.size == 0: + raise ValueError("There aren't any elements to reflect in `array`") + for axis, (pad_before, pad_after) in enumerate(pad_width): # Recursive padding along any axis where `pad_amt` is too large # for indexing tricks. We can only safely pad the original axis diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index 55cd24a14..a44722b56 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -1013,6 +1013,10 @@ class TestValueError1(object): assert_raises(ValueError, pad, arr, ((-2, 3), (3, 2)), **kwargs) + def test_check_empty_array(self): + assert_raises(ValueError, pad, [], 4, mode='reflect') + assert_raises(ValueError, pad, np.ndarray(0), 4, mode='reflect') + class TestValueError2(object): def test_check_negative_pad_amount(self): |