diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2016-09-17 18:22:37 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2016-09-17 18:25:09 -0400 |
commit | f28957d2a9411958a6952687be9c4dcd1be2a23a (patch) | |
tree | 6ce535d9d2a34737054af6a2cbb8e160a7c512b1 /numpy/lib/tests/test_arraypad.py | |
parent | c90d7c94fd2077d0beca48fa89a423da2b0bb663 (diff) | |
download | numpy-f28957d2a9411958a6952687be9c4dcd1be2a23a.tar.gz |
BUG: lib: Simplify (and fix) pad's handling of the pad_width
Simplify the expansion of the pad_width argument by using `broadcast_to()`.
This fixes the problem reported in gh-7808, where, for example,
`pad_width=((1, 2),)` resulted in an error.
Closes gh-7808.
Diffstat (limited to 'numpy/lib/tests/test_arraypad.py')
-rw-r--r-- | numpy/lib/tests/test_arraypad.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py index 9ad05906d..d037962e6 100644 --- a/numpy/lib/tests/test_arraypad.py +++ b/numpy/lib/tests/test_arraypad.py @@ -914,6 +914,24 @@ class TestEdge(TestCase): ) assert_array_equal(a, b) + def test_check_width_shape_1_2(self): + # Check a pad_width of the form ((1, 2),). + # Regression test for issue gh-7808. + a = np.array([1, 2, 3]) + padded = pad(a, ((1, 2),), 'edge') + expected = np.array([1, 1, 2, 3, 3, 3]) + assert_array_equal(padded, expected) + + a = np.array([[1, 2, 3], [4, 5, 6]]) + padded = pad(a, ((1, 2),), 'edge') + expected = pad(a, ((1, 2), (1, 2)), 'edge') + assert_array_equal(padded, expected) + + a = np.arange(24).reshape(2, 3, 4) + padded = pad(a, ((1, 2),), 'edge') + expected = pad(a, ((1, 2), (1, 2), (1, 2)), 'edge') + assert_array_equal(padded, expected) + class TestZeroPadWidth(TestCase): def test_zero_pad_width(self): |