From c6ce294f6feeebcdf67b238564c770387be933a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20B=C3=B8=20Fl=C3=B8ystad?= Date: Fri, 5 Jul 2013 17:35:45 +0200 Subject: BUG: Allow to pad arrays by zero entries. np.pad will now accept a pad_width containing zeros. The functionality was already implemented, but validation of input was too strict. --- numpy/lib/arraypad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py index c80f6f54d..90b5fcfcd 100644 --- a/numpy/lib/arraypad.py +++ b/numpy/lib/arraypad.py @@ -1079,7 +1079,7 @@ def _validate_lengths(narray, number_elements): normshp = _normalize_shape(narray, number_elements) for i in normshp: chk = [1 if x is None else x for x in i] - chk = [1 if x > 0 else -1 for x in chk] + chk = [1 if x >= 0 else -1 for x in chk] if (chk[0] < 0) or (chk[1] < 0): fmt = "%s cannot contain negative values." raise ValueError(fmt % (number_elements,)) -- cgit v1.2.1 From ea45134062693723c2258b862f87d3750a8dc564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20B=C3=B8=20Fl=C3=B8ystad?= Date: Fri, 5 Jul 2013 18:17:26 +0200 Subject: TST: New test to ensure np.pad allows pad_width of zero. --- numpy/lib/tests/test_arraypad.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index c6acd4db0..ec96f5c8c 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -486,6 +486,14 @@ class TestEdge(TestCase): assert_array_equal(a, b) +class TestZeroPadWidth(TestCase): + def test_zero_pad_width(self): + arr = np.arange(30) + arr = np.reshape(arr, (6, 5)) + for pad_width in (0, (0, 0), ((0, 0), (0, 0))): + assert_array_equal(arr, pad(arr, pad_width, mode='constant')) + + class ValueError1(TestCase): def test_check_simple(self): arr = np.arange(30) -- cgit v1.2.1