summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@gmail.com>2019-03-15 14:18:22 -0700
committerGitHub <noreply@github.com>2019-03-15 14:18:22 -0700
commit5e9c419a6d41eb9d544b6d87dd621ad5b346a0fa (patch)
tree5bacba0aa0d79c9a9676f3c25f5932d3749126b5 /numpy
parentba734f3160419771f82bb1f45c60d4871f2efd72 (diff)
parent9a037558d66f54b27acd133b8b8e92f76717a849 (diff)
downloadnumpy-5e9c419a6d41eb9d544b6d87dd621ad5b346a0fa.tar.gz
Merge pull request #4808 from stefanv/pad_mode_positional
ENH: Make the `mode` parameter of np.pad default to 'constant'
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/arraypad.py8
-rw-r--r--numpy/lib/tests/test_arraypad.py7
2 files changed, 7 insertions, 8 deletions
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py
index b236cc449..630767dc5 100644
--- a/numpy/lib/arraypad.py
+++ b/numpy/lib/arraypad.py
@@ -957,12 +957,12 @@ def _as_pairs(x, ndim, as_index=False):
# Public functions
-def _pad_dispatcher(array, pad_width, mode, **kwargs):
+def _pad_dispatcher(array, pad_width, mode=None, **kwargs):
return (array,)
@array_function_dispatch(_pad_dispatcher, module='numpy')
-def pad(array, pad_width, mode, **kwargs):
+def pad(array, pad_width, mode='constant', **kwargs):
"""
Pads an array.
@@ -977,10 +977,10 @@ def pad(array, pad_width, mode, **kwargs):
((before, after),) yields same before and after pad for each axis.
(pad,) or int is a shortcut for before = after = pad width for all
axes.
- mode : str or function
+ mode : str or function, optional
One of the following string values or a user supplied function.
- 'constant'
+ 'constant' (default)
Pads with a constant value.
'edge'
Pads with the edge values of array.
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py
index a9030e737..b7393294a 100644
--- a/numpy/lib/tests/test_arraypad.py
+++ b/numpy/lib/tests/test_arraypad.py
@@ -1249,10 +1249,9 @@ def test_kwargs(mode):
np.pad([1, 2, 3], 1, mode, **{key: value})
-def test_missing_mode():
- match = "missing 1 required positional argument: 'mode'"
- with pytest.raises(TypeError, match=match):
- np.pad(np.ones((5, 6)), 4)
+def test_constant_zero_default():
+ arr = np.array([1, 1])
+ assert_array_equal(np.pad(arr, 2), [0, 0, 1, 1, 0, 0])
@pytest.mark.parametrize("mode", _all_modes.keys())