From 77d911ff03b43603cd3afcfc2f7b72f8df86a1fb Mon Sep 17 00:00:00 2001 From: chiffa Date: Sat, 27 Feb 2016 17:39:29 -0500 Subject: [PATCH 1/2] TST: added a test for constant padding on 4 sides of a 2d array This test exposes padding bug described in the issue #7353 --- numpy/lib/tests/test_arraypad.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index f19a0b13abad..9ad05906d0e7 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -477,6 +477,19 @@ def test_check_constant_odd_pad_amount(self): ) assert_allclose(test, expected) + def test_check_constant_pad_2d(self): + arr = np.arange(4).reshape(2, 2) + test = np.lib.pad(arr, ((1, 2), (1, 3)), mode='constant', + constant_values=((1, 2), (3, 4))) + expected = np.array( + [[3, 1, 1, 4, 4, 4], + [3, 0, 1, 4, 4, 4], + [3, 2, 3, 4, 4, 4], + [3, 2, 2, 4, 4, 4], + [3, 2, 2, 4, 4, 4]] + ) + assert_allclose(test, expected) + class TestLinearRamp(TestCase): def test_check_simple(self): From 32f8393b8c4b6cadadab10f785eceb406e8cef90 Mon Sep 17 00:00:00 2001 From: chiffa Date: Sat, 27 Feb 2016 17:38:28 -0500 Subject: [PATCH 2/2] BUG: constant padding expected wrong type in constant_values Constant padding on 4 sides of a 2d array expected a numpy ndarray, and not a ndarray like (tuple, list, ...) Detailed description is in the issue #7353 --- 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 c30ef6bf5828..3cfb1052a2aa 100644 --- a/numpy/lib/arraypad.py +++ b/numpy/lib/arraypad.py @@ -1052,7 +1052,7 @@ def _normalize_shape(ndarray, shape, cast_to_int=True): arr = arr.repeat(2, axis=1) elif arr.shape[0] == ndims: # Input correctly formatted, pass it on as `arr` - arr = shape + pass else: fmt = "Unable to create correctly shaped tuple from %s" raise ValueError(fmt % (shape,))