diff options
author | Iryna Shcherbina <ishcherb@redhat.com> | 2017-09-01 15:21:08 +0200 |
---|---|---|
committer | Iryna Shcherbina <ishcherb@redhat.com> | 2017-09-01 18:53:15 +0200 |
commit | b6bbd74bc1158a59eaa0c2e20fe2f66c52f07fb6 (patch) | |
tree | ded5815ec56484d42d34e365386825a784a79b0d /numpy/lib/arraypad.py | |
parent | c25f3827cf2226db257b3195d5c8b0b2e91ce5a4 (diff) | |
download | numpy-b6bbd74bc1158a59eaa0c2e20fe2f66c52f07fb6.tar.gz |
BUG: fix padding an empty array in reflect mode.
Check that axes with non-zero padding are non-empty.
Diffstat (limited to 'numpy/lib/arraypad.py')
-rw-r--r-- | numpy/lib/arraypad.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py index 294a68950..842f3a9fe 100644 --- a/numpy/lib/arraypad.py +++ b/numpy/lib/arraypad.py @@ -1406,10 +1406,15 @@ 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): + if narray.shape[axis] == 0: + # Axes with non-zero padding cannot be empty. + if pad_before > 0 or pad_after > 0: + raise ValueError("There aren't any elements to reflect" + " in axis {} of `array`".format(axis)) + # Skip zero padding on empty axes. + continue + # Recursive padding along any axis where `pad_amt` is too large # for indexing tricks. We can only safely pad the original axis # length, to keep the period of the reflections consistent. |